home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Mac / Modules / ctl / Ctlmodule.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-01  |  16.8 KB  |  703 lines  |  [TEXT/CWIE]

  1.  
  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.  
  16. extern PyObject *ResObj_New(Handle);
  17. extern int ResObj_Convert(PyObject *, Handle *);
  18. extern PyObject *OptResObj_New(Handle);
  19. extern int OptResObj_Convert(PyObject *, Handle *);
  20.  
  21. extern PyObject *WinObj_New(WindowPtr);
  22. extern int WinObj_Convert(PyObject *, WindowPtr *);
  23. extern PyTypeObject Window_Type;
  24. #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
  25.  
  26. extern PyObject *DlgObj_New(DialogPtr);
  27. extern int DlgObj_Convert(PyObject *, DialogPtr *);
  28. extern PyTypeObject Dialog_Type;
  29. #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
  30.  
  31. extern PyObject *MenuObj_New(MenuHandle);
  32. extern int MenuObj_Convert(PyObject *, MenuHandle *);
  33.  
  34. extern PyObject *CtlObj_New(ControlHandle);
  35. extern int CtlObj_Convert(PyObject *, ControlHandle *);
  36.  
  37. extern PyObject *GrafObj_New(GrafPtr);
  38. extern int GrafObj_Convert(PyObject *, GrafPtr *);
  39.  
  40. extern PyObject *BMObj_New(BitMapPtr);
  41. extern int BMObj_Convert(PyObject *, BitMapPtr *);
  42.  
  43. extern 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.  
  49. extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
  50.  
  51. #ifdef THINK_C
  52. #define  ControlActionUPP ProcPtr
  53. #endif
  54.  
  55. static PyObject *Ctl_Error;
  56.  
  57. /* ---------------------- Object type Control ----------------------- */
  58.  
  59. PyTypeObject Control_Type;
  60.  
  61. #define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
  62.  
  63. typedef struct ControlObject {
  64.     PyObject_HEAD
  65.     ControlHandle ob_itself;
  66. } ControlObject;
  67.  
  68. PyObject *CtlObj_New(itself)
  69.     ControlHandle itself;
  70. {
  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. }
  79. CtlObj_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.  
  92. static void CtlObj_dealloc(self)
  93.     ControlObject *self;
  94. {
  95.     if (self->ob_itself) SetCRefCon(self->ob_itself, (long)0); /* Make it forget about us */
  96.     PyMem_DEL(self);
  97. }
  98.  
  99. static 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.  
  112. static 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.  
  125. static 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.  
  138. static 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.  
  154. static 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.  
  172. static PyObject *CtlObj_DragControl(_self, _args)
  173.     ControlObject *_self;
  174.     PyObject *_args;
  175. {
  176.     PyObject *_res = NULL;
  177.     Point startPoint;
  178.     Rect limitRect;
  179.     Rect slopRect;
  180.     DragConstraint axis;
  181.     if (!PyArg_ParseTuple(_args, "O&O&O&h",
  182.                           PyMac_GetPoint, &startPoint,
  183.                           PyMac_GetRect, &limitRect,
  184.                           PyMac_GetRect, &slopRect,
  185.                           &axis))
  186.         return NULL;
  187.     DragControl(_self->ob_itself,
  188.                 startPoint,
  189.                 &limitRect,
  190.                 &slopRect,
  191.                 axis);
  192.     Py_INCREF(Py_None);
  193.     _res = Py_None;
  194.     return _res;
  195. }
  196.  
  197. static PyObject *CtlObj_TestControl(_self, _args)
  198.     ControlObject *_self;
  199.     PyObject *_args;
  200. {
  201.     PyObject *_res = NULL;
  202.     ControlPartCode _rv;
  203.     Point thePoint;
  204.     if (!PyArg_ParseTuple(_args, "O&",
  205.                           PyMac_GetPoint, &thePoint))
  206.         return NULL;
  207.     _rv = TestControl(_self->ob_itself,
  208.                       thePoint);
  209.     _res = Py_BuildValue("h",
  210.                          _rv);
  211.     return _res;
  212. }
  213.  
  214. static 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.  
  233. static 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.  
  252. static PyObject *CtlObj_SetControlTitle(_self, _args)
  253.     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;
  261.     SetControlTitle(_self->ob_itself,
  262.                     title);
  263.     Py_INCREF(Py_None);
  264.     _res = Py_None;
  265.     return _res;
  266. }
  267.  
  268. static PyObject *CtlObj_GetControlTitle(_self, _args)
  269.     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;
  277.     GetControlTitle(_self->ob_itself,
  278.                     title);
  279.     Py_INCREF(Py_None);
  280.     _res = Py_None;
  281.     return _res;
  282. }
  283.  
  284. static PyObject *CtlObj_GetControlValue(_self, _args)
  285.     ControlObject *_self;
  286.     PyObject *_args;
  287. {
  288.     PyObject *_res = NULL;
  289.     SInt16 _rv;
  290.     if (!PyArg_ParseTuple(_args, ""))
  291.         return NULL;
  292.     _rv = GetControlValue(_self->ob_itself);
  293.     _res = Py_BuildValue("h",
  294.                          _rv);
  295.     return _res;
  296. }
  297.  
  298. static PyObject *CtlObj_SetControlValue(_self, _args)
  299.     ControlObject *_self;
  300.     PyObject *_args;
  301. {
  302.     PyObject *_res = NULL;
  303.     SInt16 newValue;
  304.     if (!PyArg_ParseTuple(_args, "h",
  305.                           &newValue))
  306.         return NULL;
  307.     SetControlValue(_self->ob_itself,
  308.                     newValue);
  309.     Py_INCREF(Py_None);
  310.     _res = Py_None;
  311.     return _res;
  312. }
  313.  
  314. static PyObject *CtlObj_GetControlMinimum(_self, _args)
  315.     ControlObject *_self;
  316.     PyObject *_args;
  317. {
  318.     PyObject *_res = NULL;
  319.     SInt16 _rv;
  320.     if (!PyArg_ParseTuple(_args, ""))
  321.         return NULL;
  322.     _rv = GetControlMinimum(_self->ob_itself);
  323.     _res = Py_BuildValue("h",
  324.                          _rv);
  325.     return _res;
  326. }
  327.  
  328. static PyObject *CtlObj_SetControlMinimum(_self, _args)
  329.     ControlObject *_self;
  330.     PyObject *_args;
  331. {
  332.     PyObject *_res = NULL;
  333.     SInt16 newMinimum;
  334.     if (!PyArg_ParseTuple(_args, "h",
  335.                           &newMinimum))
  336.         return NULL;
  337.     SetControlMinimum(_self->ob_itself,
  338.                       newMinimum);
  339.     Py_INCREF(Py_None);
  340.     _res = Py_None;
  341.     return _res;
  342. }
  343.  
  344. static PyObject *CtlObj_GetControlMaximum(_self, _args)
  345.     ControlObject *_self;
  346.     PyObject *_args;
  347. {
  348.     PyObject *_res = NULL;
  349.     SInt16 _rv;
  350.     if (!PyArg_ParseTuple(_args, ""))
  351.         return NULL;
  352.     _rv = GetControlMaximum(_self->ob_itself);
  353.     _res = Py_BuildValue("h",
  354.                          _rv);
  355.     return _res;
  356. }
  357.  
  358. static PyObject *CtlObj_SetControlMaximum(_self, _args)
  359.     ControlObject *_self;
  360.     PyObject *_args;
  361. {
  362.     PyObject *_res = NULL;
  363.     SInt16 newMaximum;
  364.     if (!PyArg_ParseTuple(_args, "h",
  365.                           &newMaximum))
  366.         return NULL;
  367.     SetControlMaximum(_self->ob_itself,
  368.                       newMaximum);
  369.     Py_INCREF(Py_None);
  370.     _res = Py_None;
  371.     return _res;
  372. }
  373.  
  374. static PyObject *CtlObj_GetControlVariant(_self, _args)
  375.     ControlObject *_self;
  376.     PyObject *_args;
  377. {
  378.     PyObject *_res = NULL;
  379.     SInt16 _rv;
  380.     if (!PyArg_ParseTuple(_args, ""))
  381.         return NULL;
  382.     _rv = GetControlVariant(_self->ob_itself);
  383.     _res = Py_BuildValue("h",
  384.                          _rv);
  385.     return _res;
  386. }
  387.  
  388. static 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.  
  402. static PyObject *CtlObj_SetControlReference(_self, _args)
  403.     ControlObject *_self;
  404.     PyObject *_args;
  405. {
  406.     PyObject *_res = NULL;
  407.     SInt32 data;
  408.     if (!PyArg_ParseTuple(_args, "l",
  409.                           &data))
  410.         return NULL;
  411.     SetControlReference(_self->ob_itself,
  412.                         data);
  413.     Py_INCREF(Py_None);
  414.     _res = Py_None;
  415.     return _res;
  416. }
  417.  
  418. static PyObject *CtlObj_GetControlReference(_self, _args)
  419.     ControlObject *_self;
  420.     PyObject *_args;
  421. {
  422.     PyObject *_res = NULL;
  423.     SInt32 _rv;
  424.     if (!PyArg_ParseTuple(_args, ""))
  425.         return NULL;
  426.     _rv = GetControlReference(_self->ob_itself);
  427.     _res = Py_BuildValue("l",
  428.                          _rv);
  429.     return _res;
  430. }
  431.  
  432. static 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.  
  442. static 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.  
  461. static PyMethodDef CtlObj_methods[] = {
  462.     {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
  463.      "() -> None"},
  464.     {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
  465.      "() -> None"},
  466.     {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
  467.      "() -> None"},
  468.     {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
  469.      "(ControlPartCode hiliteState) -> None"},
  470.     {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
  471.      "(Point thePoint) -> (ControlPartCode _rv)"},
  472.     {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
  473.      "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
  474.     {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
  475.      "(Point thePoint) -> (ControlPartCode _rv)"},
  476.     {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
  477.      "(SInt16 h, SInt16 v) -> None"},
  478.     {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
  479.      "(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"},
  484.     {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
  485.      "() -> (SInt16 _rv)"},
  486.     {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
  487.      "(SInt16 newValue) -> None"},
  488.     {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
  489.      "() -> (SInt16 _rv)"},
  490.     {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
  491.      "(SInt16 newMinimum) -> None"},
  492.     {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
  493.      "() -> (SInt16 _rv)"},
  494.     {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
  495.      "(SInt16 newMaximum) -> None"},
  496.     {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
  497.      "() -> (SInt16 _rv)"},
  498.     {"SetControlAction", (PyCFunction)CtlObj_SetControlAction, 1,
  499.      "() -> None"},
  500.     {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
  501.      "(SInt32 data) -> None"},
  502.     {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
  503.      "() -> (SInt32 _rv)"},
  504.     {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
  505.      "Return this Control as a Resource"},
  506.     {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
  507.      "() -> None"},
  508.     {NULL, NULL, 0}
  509. };
  510.  
  511. PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
  512.  
  513. static 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.  
  522. PyTypeObject 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.  
  538. static 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;
  548.     SInt16 value;
  549.     SInt16 min;
  550.     SInt16 max;
  551.     SInt16 procID;
  552.     SInt32 refCon;
  553.     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.  
  578. static PyObject *Ctl_GetNewControl(_self, _args)
  579.     PyObject *_self;
  580.     PyObject *_args;
  581. {
  582.     PyObject *_res = NULL;
  583.     ControlHandle _rv;
  584.     SInt16 controlID;
  585.     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.  
  597. static 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.  
  612. static PyObject *Ctl_UpdateControls(_self, _args)
  613.     PyObject *_self;
  614.     PyObject *_args;
  615. {
  616.     PyObject *_res = NULL;
  617.     WindowPtr theWindow;
  618.     RgnHandle updateRegion;
  619.     if (!PyArg_ParseTuple(_args, "O&O&",
  620.                           WinObj_Convert, &theWindow,
  621.                           ResObj_Convert, &updateRegion))
  622.         return NULL;
  623.     UpdateControls(theWindow,
  624.                    updateRegion);
  625.     Py_INCREF(Py_None);
  626.     _res = Py_None;
  627.     return _res;
  628. }
  629.  
  630. static PyObject *Ctl_FindControl(_self, _args)
  631.     PyObject *_self;
  632.     PyObject *_args;
  633. {
  634.     PyObject *_res = NULL;
  635.     ControlPartCode _rv;
  636.     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.  
  652. static PyMethodDef Ctl_methods[] = {
  653.     {"NewControl", (PyCFunction)Ctl_NewControl, 1,
  654.      "(WindowPtr theWindow, Rect boundsRect, Str255 title, Boolean visible, SInt16 value, SInt16 min, SInt16 max, SInt16 procID, SInt32 refCon) -> (ControlHandle _rv)"},
  655.     {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
  656.      "(SInt16 controlID, WindowPtr owner) -> (ControlHandle _rv)"},
  657.     {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
  658.      "(WindowPtr theWindow) -> None"},
  659.     {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
  660.      "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
  661.     {"FindControl", (PyCFunction)Ctl_FindControl, 1,
  662.      "(Point thePoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
  663.     {NULL, NULL, 0}
  664. };
  665.  
  666.  
  667.  
  668. PyObject *
  669. CtlObj_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.  
  685. void 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.  
  703.