Commit 80716f0e authored by Jack Jansen's avatar Jack Jansen

Set autodispose only if RefCon isn't set yet on the window. This way we don't...

Set autodispose only if RefCon isn't set yet on the window. This way we don't accidentally dispose of windows that are actually dialogs-in-disguise.
parent 4550b00c
...@@ -45,8 +45,12 @@ PyObject *WinObj_New(itself) ...@@ -45,8 +45,12 @@ PyObject *WinObj_New(itself)
it = PyObject_NEW(WindowObject, &Window_Type); it = PyObject_NEW(WindowObject, &Window_Type);
if (it == NULL) return NULL; if (it == NULL) return NULL;
it->ob_itself = itself; it->ob_itself = itself;
SetWRefCon(itself, (long)it); it->ob_freeit = NULL;
it->ob_freeit = PyMac_AutoDisposeWindow; if (GetWRefCon(itself) == 0)
{
SetWRefCon(itself, (long)it);
it->ob_freeit = PyMac_AutoDisposeWindow;
}
return (PyObject *)it; return (PyObject *)it;
} }
WinObj_Convert(v, p_itself) WinObj_Convert(v, p_itself)
...@@ -73,12 +77,13 @@ WinObj_Convert(v, p_itself) ...@@ -73,12 +77,13 @@ WinObj_Convert(v, p_itself)
static void WinObj_dealloc(self) static void WinObj_dealloc(self)
WindowObject *self; WindowObject *self;
{ {
if (self->ob_itself) SetWRefCon(self->ob_itself, 0);
if (self->ob_freeit && self->ob_itself) if (self->ob_freeit && self->ob_itself)
{ {
SetWRefCon(self->ob_itself, 0);
self->ob_freeit(self->ob_itself); self->ob_freeit(self->ob_itself);
} }
self->ob_itself = NULL; self->ob_itself = NULL;
self->ob_freeit = NULL;
PyMem_DEL(self); PyMem_DEL(self);
} }
...@@ -394,6 +399,38 @@ static PyObject *WinObj_DrawNew(_self, _args) ...@@ -394,6 +399,38 @@ static PyObject *WinObj_DrawNew(_self, _args)
} }
#endif #endif
static PyObject *WinObj_PaintOne(_self, _args)
WindowObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
RgnHandle clobberedRgn;
if (!PyArg_ParseTuple(_args, "O&",
ResObj_Convert, &clobberedRgn))
return NULL;
PaintOne(_self->ob_itself,
clobberedRgn);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *WinObj_PaintBehind(_self, _args)
WindowObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
RgnHandle clobberedRgn;
if (!PyArg_ParseTuple(_args, "O&",
ResObj_Convert, &clobberedRgn))
return NULL;
PaintBehind(_self->ob_itself,
clobberedRgn);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *WinObj_CalcVis(_self, _args) static PyObject *WinObj_CalcVis(_self, _args)
WindowObject *_self; WindowObject *_self;
PyObject *_args; PyObject *_args;
...@@ -407,6 +444,22 @@ static PyObject *WinObj_CalcVis(_self, _args) ...@@ -407,6 +444,22 @@ static PyObject *WinObj_CalcVis(_self, _args)
return _res; return _res;
} }
static PyObject *WinObj_CalcVisBehind(_self, _args)
WindowObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
RgnHandle clobberedRgn;
if (!PyArg_ParseTuple(_args, "O&",
ResObj_Convert, &clobberedRgn))
return NULL;
CalcVisBehind(_self->ob_itself,
clobberedRgn);
Py_INCREF(Py_None);
_res = Py_None;
return _res;
}
static PyObject *WinObj_BringToFront(_self, _args) static PyObject *WinObj_BringToFront(_self, _args)
WindowObject *_self; WindowObject *_self;
PyObject *_args; PyObject *_args;
...@@ -1032,6 +1085,26 @@ static PyObject *WinObj_IsWindowPathSelectClick(_self, _args) ...@@ -1032,6 +1085,26 @@ static PyObject *WinObj_IsWindowPathSelectClick(_self, _args)
return _res; return _res;
} }
static PyObject *WinObj_WindowPathSelect(_self, _args)
WindowObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
OSStatus _err;
MenuHandle menu;
SInt32 outMenuResult;
if (!PyArg_ParseTuple(_args, "O&",
MenuObj_Convert, &menu))
return NULL;
_err = WindowPathSelect(_self->ob_itself,
menu,
&outMenuResult);
if (_err != noErr) return PyMac_Error(_err);
_res = Py_BuildValue("l",
outMenuResult);
return _res;
}
static PyObject *WinObj_HiliteWindowFrameForDrag(_self, _args) static PyObject *WinObj_HiliteWindowFrameForDrag(_self, _args)
WindowObject *_self; WindowObject *_self;
PyObject *_args; PyObject *_args;
...@@ -1242,6 +1315,29 @@ static PyObject *WinObj_GetWindowBounds(_self, _args) ...@@ -1242,6 +1315,29 @@ static PyObject *WinObj_GetWindowBounds(_self, _args)
return _res; return _res;
} }
static PyObject *WinObj_ResizeWindow(_self, _args)
WindowObject *_self;
PyObject *_args;
{
PyObject *_res = NULL;
Boolean _rv;
Point startPoint;
Rect sizeConstraints;
Rect newContentRect;
if (!PyArg_ParseTuple(_args, "O&O&",
PyMac_GetPoint, &startPoint,
PyMac_GetRect, &sizeConstraints))
return NULL;
_rv = ResizeWindow(_self->ob_itself,
startPoint,
&sizeConstraints,
&newContentRect);
_res = Py_BuildValue("bO&",
_rv,
PyMac_BuildRect, &newContentRect);
return _res;
}
static PyObject *WinObj_SetWindowBounds(_self, _args) static PyObject *WinObj_SetWindowBounds(_self, _args)
WindowObject *_self; WindowObject *_self;
PyObject *_args; PyObject *_args;
...@@ -1860,8 +1956,14 @@ static PyMethodDef WinObj_methods[] = { ...@@ -1860,8 +1956,14 @@ static PyMethodDef WinObj_methods[] = {
{"DrawNew", (PyCFunction)WinObj_DrawNew, 1, {"DrawNew", (PyCFunction)WinObj_DrawNew, 1,
"(Boolean update) -> None"}, "(Boolean update) -> None"},
#endif #endif
{"PaintOne", (PyCFunction)WinObj_PaintOne, 1,
"(RgnHandle clobberedRgn) -> None"},
{"PaintBehind", (PyCFunction)WinObj_PaintBehind, 1,
"(RgnHandle clobberedRgn) -> None"},
{"CalcVis", (PyCFunction)WinObj_CalcVis, 1, {"CalcVis", (PyCFunction)WinObj_CalcVis, 1,
"() -> None"}, "() -> None"},
{"CalcVisBehind", (PyCFunction)WinObj_CalcVisBehind, 1,
"(RgnHandle clobberedRgn) -> None"},
{"BringToFront", (PyCFunction)WinObj_BringToFront, 1, {"BringToFront", (PyCFunction)WinObj_BringToFront, 1,
"() -> None"}, "() -> None"},
{"SendBehind", (PyCFunction)WinObj_SendBehind, 1, {"SendBehind", (PyCFunction)WinObj_SendBehind, 1,
...@@ -1942,6 +2044,8 @@ static PyMethodDef WinObj_methods[] = { ...@@ -1942,6 +2044,8 @@ static PyMethodDef WinObj_methods[] = {
"(Boolean modified) -> None"}, "(Boolean modified) -> None"},
{"IsWindowPathSelectClick", (PyCFunction)WinObj_IsWindowPathSelectClick, 1, {"IsWindowPathSelectClick", (PyCFunction)WinObj_IsWindowPathSelectClick, 1,
"(EventRecord event) -> (Boolean _rv)"}, "(EventRecord event) -> (Boolean _rv)"},
{"WindowPathSelect", (PyCFunction)WinObj_WindowPathSelect, 1,
"(MenuHandle menu) -> (SInt32 outMenuResult)"},
{"HiliteWindowFrameForDrag", (PyCFunction)WinObj_HiliteWindowFrameForDrag, 1, {"HiliteWindowFrameForDrag", (PyCFunction)WinObj_HiliteWindowFrameForDrag, 1,
"(Boolean hilited) -> None"}, "(Boolean hilited) -> None"},
{"TransitionWindow", (PyCFunction)WinObj_TransitionWindow, 1, {"TransitionWindow", (PyCFunction)WinObj_TransitionWindow, 1,
...@@ -1964,6 +2068,8 @@ static PyMethodDef WinObj_methods[] = { ...@@ -1964,6 +2068,8 @@ static PyMethodDef WinObj_methods[] = {
"(Boolean collapse) -> None"}, "(Boolean collapse) -> None"},
{"GetWindowBounds", (PyCFunction)WinObj_GetWindowBounds, 1, {"GetWindowBounds", (PyCFunction)WinObj_GetWindowBounds, 1,
"(WindowRegionCode regionCode) -> (Rect globalBounds)"}, "(WindowRegionCode regionCode) -> (Rect globalBounds)"},
{"ResizeWindow", (PyCFunction)WinObj_ResizeWindow, 1,
"(Point startPoint, Rect sizeConstraints) -> (Boolean _rv, Rect newContentRect)"},
{"SetWindowBounds", (PyCFunction)WinObj_SetWindowBounds, 1, {"SetWindowBounds", (PyCFunction)WinObj_SetWindowBounds, 1,
"(WindowRegionCode regionCode, Rect globalBounds) -> None"}, "(WindowRegionCode regionCode, Rect globalBounds) -> None"},
{"RepositionWindow", (PyCFunction)WinObj_RepositionWindow, 1, {"RepositionWindow", (PyCFunction)WinObj_RepositionWindow, 1,
...@@ -2767,7 +2873,7 @@ WinObj_WhichWindow(w) ...@@ -2767,7 +2873,7 @@ WinObj_WhichWindow(w)
Py_INCREF(it); Py_INCREF(it);
} else { } else {
it = (PyObject *) GetWRefCon(w); it = (PyObject *) GetWRefCon(w);
if (it == NULL || ((WindowObject *)it)->ob_itself != w) { if (it == NULL || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) {
it = WinObj_New(w); it = WinObj_New(w);
((WindowObject *)it)->ob_freeit = NULL; ((WindowObject *)it)->ob_freeit = NULL;
} else { } else {
......
...@@ -84,7 +84,7 @@ WinObj_WhichWindow(w) ...@@ -84,7 +84,7 @@ WinObj_WhichWindow(w)
Py_INCREF(it); Py_INCREF(it);
} else { } else {
it = (PyObject *) GetWRefCon(w); it = (PyObject *) GetWRefCon(w);
if (it == NULL || ((WindowObject *)it)->ob_itself != w) { if (it == NULL || ((WindowObject *)it)->ob_itself != w || !WinObj_Check(it)) {
it = WinObj_New(w); it = WinObj_New(w);
((WindowObject *)it)->ob_freeit = NULL; ((WindowObject *)it)->ob_freeit = NULL;
} else { } else {
...@@ -103,8 +103,12 @@ class MyObjectDefinition(GlobalObjectDefinition): ...@@ -103,8 +103,12 @@ class MyObjectDefinition(GlobalObjectDefinition):
Output("void (*ob_freeit)(%s ptr);", self.itselftype) Output("void (*ob_freeit)(%s ptr);", self.itselftype)
def outputInitStructMembers(self): def outputInitStructMembers(self):
GlobalObjectDefinition.outputInitStructMembers(self) GlobalObjectDefinition.outputInitStructMembers(self)
Output("it->ob_freeit = NULL;")
Output("if (GetWRefCon(itself) == 0)")
OutLbrace()
Output("SetWRefCon(itself, (long)it);") Output("SetWRefCon(itself, (long)it);")
Output("it->ob_freeit = PyMac_AutoDisposeWindow;") Output("it->ob_freeit = PyMac_AutoDisposeWindow;")
OutRbrace()
def outputCheckConvertArg(self): def outputCheckConvertArg(self):
OutLbrace("if (DlgObj_Check(v))") OutLbrace("if (DlgObj_Check(v))")
Output("*p_itself = DlgObj_ConvertToWindow(v);") Output("*p_itself = DlgObj_ConvertToWindow(v);")
...@@ -115,12 +119,13 @@ class MyObjectDefinition(GlobalObjectDefinition): ...@@ -115,12 +119,13 @@ class MyObjectDefinition(GlobalObjectDefinition):
if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; } if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
""") """)
def outputCleanupStructMembers(self): def outputCleanupStructMembers(self):
Output("if (self->ob_itself) SetWRefCon(self->ob_itself, 0);")
Output("if (self->ob_freeit && self->ob_itself)") Output("if (self->ob_freeit && self->ob_itself)")
OutLbrace() OutLbrace()
Output("SetWRefCon(self->ob_itself, 0);")
Output("self->ob_freeit(self->ob_itself);") Output("self->ob_freeit(self->ob_itself);")
OutRbrace() OutRbrace()
Output("self->ob_itself = NULL;") Output("self->ob_itself = NULL;")
Output("self->ob_freeit = NULL;")
## def outputFreeIt(self, itselfname): ## def outputFreeIt(self, itselfname):
## Output("DisposeWindow(%s);", itselfname) ## Output("DisposeWindow(%s);", itselfname)
# From here on it's basically all boiler plate... # From here on it's basically all boiler plate...
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment