summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/ctl/ctlsupport.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1999-03-13 23:07:32 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1999-03-13 23:07:32 (GMT)
commit8387af65a9152ae2b286b6955ea51157e54aafda (patch)
tree0b4037f25179bc3e2ef4363955d8470b2e3c440f /Mac/Modules/ctl/ctlsupport.py
parentd5138caba5fac644571cd7fa013d1ab0d4f867b6 (diff)
downloadcpython-8387af65a9152ae2b286b6955ea51157e54aafda.zip
cpython-8387af65a9152ae2b286b6955ea51157e54aafda.tar.gz
cpython-8387af65a9152ae2b286b6955ea51157e54aafda.tar.bz2
If a control has no refcon pointing back to the Python object we create a new
Python object. This needs a new bgenObjectDefinition.py, which implements compare and hash functions.
Diffstat (limited to 'Mac/Modules/ctl/ctlsupport.py')
-rw-r--r--Mac/Modules/ctl/ctlsupport.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/Mac/Modules/ctl/ctlsupport.py b/Mac/Modules/ctl/ctlsupport.py
index 3ba6778..8d966f9 100644
--- a/Mac/Modules/ctl/ctlsupport.py
+++ b/Mac/Modules/ctl/ctlsupport.py
@@ -89,18 +89,33 @@ extern void clrtrackfunc(void); /* forward */
"""
finalstuff = finalstuff + """
+PyObject *CtlObj_NewUnmanaged(itself)
+ ControlHandle itself;
+{
+ ControlObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(ControlObject, &Control_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ return (PyObject *)it;
+}
+
PyObject *
CtlObj_WhichControl(ControlHandle c)
{
PyObject *it;
- /* XXX What if we find a control belonging to some other package? */
if (c == NULL)
- it = NULL;
- else
- it = (PyObject *) GetControlReference(c);
- if (it == NULL || ((ControlObject *)it)->ob_itself != c)
it = Py_None;
+ else {
+ it = (PyObject *) GetControlReference(c);
+ /*
+ ** If the refcon is zero or doesn't point back to the Python object
+ ** the control is not ours. Return a temporary object.
+ */
+ if (it == NULL || ((ControlObject *)it)->ob_itself != c)
+ return CtlObj_NewUnmanaged(c);
+ }
Py_INCREF(it);
return it;
}
@@ -147,7 +162,7 @@ initstuff = initstuff + """
mytracker_upp = NewControlActionProc(mytracker);
"""
-class MyObjectDefinition(GlobalObjectDefinition):
+class MyObjectDefinition(ObjectIdentityMixin, GlobalObjectDefinition):
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
def outputInitStructMembers(self):