summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/dlg/dlgsupport.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2001-02-06 16:14:54 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2001-02-06 16:14:54 (GMT)
commit69e7f11aa871c9aac2011adf1cb1148a78f273bc (patch)
tree59ea8d5980397dd49f02180ab715246041b77d6a /Mac/Modules/dlg/dlgsupport.py
parentd6b2aeb10d9c164b2df3401374ba73102ab6d48d (diff)
downloadcpython-69e7f11aa871c9aac2011adf1cb1148a78f273bc.zip
cpython-69e7f11aa871c9aac2011adf1cb1148a78f273bc.tar.gz
cpython-69e7f11aa871c9aac2011adf1cb1148a78f273bc.tar.bz2
Added DlgObj_WhichDialog, analoguous to WhichWindow, and use this to get at dialogs.
Diffstat (limited to 'Mac/Modules/dlg/dlgsupport.py')
-rw-r--r--Mac/Modules/dlg/dlgsupport.py64
1 files changed, 60 insertions, 4 deletions
diff --git a/Mac/Modules/dlg/dlgsupport.py b/Mac/Modules/dlg/dlgsupport.py
index e537c66..ab22e18 100644
--- a/Mac/Modules/dlg/dlgsupport.py
+++ b/Mac/Modules/dlg/dlgsupport.py
@@ -53,7 +53,7 @@ static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog,
if (callback == NULL)
return 0; /* Default behavior */
Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
- args = Py_BuildValue("O&O&", WinObj_WhichWindow, dialog, PyMac_BuildEventRecord, event);
+ args = Py_BuildValue("O&O&", DlgObj_WhichDialog, dialog, PyMac_BuildEventRecord, event);
if (args == NULL)
res = NULL;
else {
@@ -104,7 +104,7 @@ static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
if (Dlg_UserItemProc_callback == NULL)
return; /* Default behavior */
Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
- args = Py_BuildValue("O&h", WinObj_WhichWindow, dialog, item);
+ args = Py_BuildValue("O&h", DlgObj_WhichDialog, dialog, item);
if (args == NULL)
res = NULL;
else {
@@ -119,7 +119,7 @@ static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
return;
}
-#if 1
+#if 0
/*
** Treating DialogObjects as WindowObjects is (I think) illegal under Carbon.
** However, as they are still identical under MacOS9 Carbon this is a problem, even
@@ -144,6 +144,36 @@ DlgObj_ConvertToWindow(self)
return GetDialogWindow(((DialogObject *)self)->ob_itself);
return NULL;
}
+/* Return the object corresponding to the dialog, or None */
+
+PyObject *
+DlgObj_WhichDialog(d)
+ DialogPtr d;
+{
+ PyObject *it;
+
+ if (d == NULL) {
+ it = Py_None;
+ Py_INCREF(it);
+ } else {
+ WindowPtr w = GetDialogWindow(d);
+
+ it = (PyObject *) GetWRefCon(w);
+ if (it == NULL || ((DialogObject *)it)->ob_itself != d || !DlgObj_Check(it)) {
+#if 0
+ /* Should do this, but we don't have an ob_freeit for dialogs yet. */
+ it = WinObj_New(w);
+ ((WindowObject *)it)->ob_freeit = NULL;
+#else
+ it = Py_None;
+ Py_INCREF(it);
+#endif
+ } else {
+ Py_INCREF(it);
+ }
+ }
+ return it;
+}
"""
@@ -153,16 +183,42 @@ class MyObjectDefinition(GlobalObjectDefinition):
GlobalObjectDefinition.__init__(self, name, prefix, itselftype)
## This won't work in Carbon, so we disable it for all MacPythons:-(
## But see the comment above:-((
- self.basechain = "&WinObj_chain"
+## self.basechain = "&WinObj_chain"
+
def outputInitStructMembers(self):
GlobalObjectDefinition.outputInitStructMembers(self)
Output("SetWRefCon(GetDialogWindow(itself), (long)it);")
+
def outputCheckNewArg(self):
Output("if (itself == NULL) return Py_None;")
+
def outputCheckConvertArg(self):
Output("if (v == Py_None) { *p_itself = NULL; return 1; }")
Output("if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);")
Output(" return 1; }")
+
+ def outputCompare(self):
+ Output()
+ Output("static int %s_compare(self, other)", self.prefix)
+ IndentLevel()
+ Output("%s *self, *other;", self.objecttype)
+ DedentLevel()
+ OutLbrace()
+ Output("if ( self->ob_itself > other->ob_itself ) return 1;")
+ Output("if ( self->ob_itself < other->ob_itself ) return -1;")
+ Output("return 0;")
+ OutRbrace()
+
+ def outputHash(self):
+ Output()
+ Output("static int %s_hash(self)", self.prefix)
+ IndentLevel()
+ Output("%s *self;", self.objecttype)
+ DedentLevel()
+ OutLbrace()
+ Output("return (int)self->ob_itself;")
+ OutRbrace()
+
def outputFreeIt(self, itselfname):
Output("DisposeDialog(%s);", itselfname)