Closing top level windows
-JM
jm at apostle.se
Fri Dec 8 07:51:36 PST 2006
I've run into a "reversed chicken-and-egg problem" when attempting to
close down an applicaiton. The application has a typical MVC design,
where its various windows act as views/controllers onto a model, which
is based on the internal data objects manipulated by my app.
This applicaiton has an Open command to open a new data file. It can
only have a single file open at a time. Hence, in order to open a new
file, I need to close down the old one first. Before I can dispose of
the data model, however, I need to get rid of any views/controllers
(ie, windows) attached to it. The windows attach to the model in their
ctors, and detatch in the dtors. They're not designed to "live" without
an associated model.
Now to the problem. When closing the old document, I first need to get
rid of its windows, before I can safely dispose of the underlying data
model. However, I've found no way to dispose of the windows explicitly.
I'm not supposed to simply delete them (and if I do, wierd things
happen). The kosher wxWidgets way is to call Destroy on the window.
However, this doesn't actually delete the window object, but merely
queue them for future deletion. They're still alive. So I can't delete
the data model, as its still being attached to the windows.
How can I synchronously accomplish this? Can I, for example, call some
Yield method that will provide "idle time" allowing the queued window
tear-down mechanism to kick in, after which I can know that the windows
are gone entirely, so I can procede tearing down the old data model and
loaing up the new one?
I really don't want to turn things "inside out" here. I merely want t
way to "synchonously" close and get rid of a bunch of windows. One
would think that's doable somehow.
-JM
More information about the wx-users
mailing list