On Fri, 8 Jul 2022 16:05:00 +0200 Quentin Cosendey wrote:
QC> Like in the doc/view sample, I want to allow the user to choose whether
QC> he wants to work in SDI, MDI or tab mode.
This is unrelated to the problem being discussed here but, FWIW, I don't
think it's a good idea to allow the user to choose this. The sample does it
just for demonstration purposes, but I've never seen a real application
that would work like this and I think one mode always works better than the
other ones for the concrete application purposes.
QC> In the menubar of all windows, I have added a pretty standard close item
QC> in the file menu, associated with the Ctrl+F4 shortcut.
QC> file->Append(wxID_CLOSE, wxGetStockLabel(wxID_CLOSE) + "\tCtrl+F4");
QC>
QC> In tab mode (using wxNotebook), this close item is the only way to close
QC> a tab, while, when running in SDI mode, I expect it to do exactly the
QC> same as closing the window with Alt+F4.
QC>
QC> That's where I observed something strange.
QC>
QC> IF I close the window with Alt+F4, the method OnCloseDocument of my
QC> wxDocument subclass is called only once, which is normal. The call comes
QC> from wxView::OnClose.
QC>
QC> However, if I close the window with Ctrl+F4, wxDocument::OnCloseDocument
QC> is called twice !
QC> It equally happens if I click on the menu item, too.
QC> ON the first time, the call comes from wxDocManager::CloseDocument, and
QC> the second time from wxView::OnClose.
This definitely looks like a bug. Looking at the code, it's all rather
confusing because wxDocument::Close() calls, via DeleteAllViews(),
wxView::Close() which calls wxView::OnClose() which calls back into
wxDocument::Close() again.
I hope there is no code which actually relies on OnCloseDocument() being
called before the views are destroyed because I just don't see how can we
fix this while preserving this behaviour. If we don't worry about breaking
such code (which really shouldn't exist, but who knows...), then the
changes in
https://github.com/wxWidgets/wxWidgets/pull/22627 could be
applied and should fix the problem (and also improve a couple of other
things in the same area).
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/