summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/win/Winmodule.c
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2000-08-25 22:17:51 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2000-08-25 22:17:51 (GMT)
commit0aee0e61f8e7b1b112500aa3ae1edb7bcb5e28b1 (patch)
treef59c9850a71fc18f23fc52df4cbb8d7ac145eb34 /Mac/Modules/win/Winmodule.c
parent0c1836f13bc3587f3a7bd74073cef63ef9a17b4c (diff)
downloadcpython-0aee0e61f8e7b1b112500aa3ae1edb7bcb5e28b1.zip
cpython-0aee0e61f8e7b1b112500aa3ae1edb7bcb5e28b1.tar.gz
cpython-0aee0e61f8e7b1b112500aa3ae1edb7bcb5e28b1.tar.bz2
Window objects now also have an AutoDispose funcpointer (set for our windows, cleared for foreign windows). Needed mainly for Carbon (where we don't know about the windows belonging to our dialogs).
Fixed a few calls that return an ExistingWindow.
Diffstat (limited to 'Mac/Modules/win/Winmodule.c')
-rw-r--r--Mac/Modules/win/Winmodule.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/Mac/Modules/win/Winmodule.c b/Mac/Modules/win/Winmodule.c
index f7890f1..c95e06b 100644
--- a/Mac/Modules/win/Winmodule.c
+++ b/Mac/Modules/win/Winmodule.c
@@ -9,6 +9,12 @@
#include "pymactoolbox.h"
#include <Windows.h>
+/* Function to dispose a window, with a "normal" calling sequence */
+static void
+PyMac_AutoDisposeWindow(WindowPtr w)
+{
+ DisposeWindow(w);
+}
static PyObject *Win_Error;
@@ -21,6 +27,7 @@ PyTypeObject Window_Type;
typedef struct WindowObject {
PyObject_HEAD
WindowPtr ob_itself;
+ void (*ob_freeit)(WindowPtr ptr);
} WindowObject;
PyObject *WinObj_New(itself)
@@ -32,6 +39,7 @@ PyObject *WinObj_New(itself)
if (it == NULL) return NULL;
it->ob_itself = itself;
SetWRefCon(itself, (long)it);
+ it->ob_freeit = PyMac_AutoDisposeWindow;
return (PyObject *)it;
}
WinObj_Convert(v, p_itself)
@@ -60,7 +68,12 @@ WinObj_Convert(v, p_itself)
static void WinObj_dealloc(self)
WindowObject *self;
{
- DisposeWindow(self->ob_itself);
+ if (self->ob_itself) SetWRefCon(self->ob_itself, 0);
+ if (self->ob_freeit && self->ob_itself)
+ {
+ self->ob_freeit(self->ob_itself);
+ }
+ self->ob_itself = NULL;
PyMem_DEL(self);
}
@@ -2079,7 +2092,7 @@ static PyObject *Win_FrontNonFloatingWindow(_self, _args)
return NULL;
_rv = FrontNonFloatingWindow();
_res = Py_BuildValue("O&",
- WinObj_New, _rv);
+ WinObj_WhichWindow, _rv);
return _res;
}
@@ -2492,15 +2505,18 @@ WinObj_WhichWindow(w)
{
PyObject *it;
- /* XXX What if we find a stdwin window or a window belonging
- to some other package? */
- if (w == NULL)
- it = NULL;
- else
- it = (PyObject *) GetWRefCon(w);
- if (it == NULL || ((WindowObject *)it)->ob_itself != w)
+ if (w == NULL) {
it = Py_None;
- Py_INCREF(it);
+ Py_INCREF(it);
+ } else {
+ it = (PyObject *) GetWRefCon(w);
+ if (it == NULL || ((WindowObject *)it)->ob_itself != w) {
+ it = WinObj_New(w);
+ ((WindowObject *)it)->ob_freeit = NULL;
+ } else {
+ Py_INCREF(it);
+ }
+ }
return it;
}