Closing Frames and Applications

In short the application and how it is created

Assuming a multiframe application, where each opened document gets at least one view created, which is placed in a new created frame. Opening document happens via document and view templates. The a2dDocumentTemplate makes the connection between file extension/contents and the document object to be created in your application. After that there the a2dViewTemplate is used to create the views on that specific document. And during the process the a2dViewConnector is used to organize how the views will be attached to the GUI by using existing or newly created windows and/or frames.

The sample like this

In the end we have several Frames open, which have an attached view to display parts of the documents. There can be several frames having views to display parts of the same document, and also views can display part of all document.

close what

So what will happen when you close a frame. Often there will be two situation. When you start your application, there will be one frame, mentioned the parent frame. This frame might display all opened documents as icons are lines of text. Every document opened will result in an extra frame being created, which will be a child frame of the parent frame. At the same time the application is adding an icon to the parent frame. Exiting the application is by closing the parent frame, which will close all child frames. But closing a child frame does not mean exiting the application, instead it should only close a view and maybe the document.

closing a view on a document

Closing a child frame, which displays (using a view) part of a document, should at least destroy the frame and close the view. Depending upon the application, what will happen more. For instance if there are several views on the document, all displaying different part or different information about the document, closing one view might be the end of the action. But if the document was modified, and this was the last view on the document, normally the user should be asked if he wants to save the modified document. And the user might decide to veto this action, leaving the frame and view intact. Also it would be possible that closing one view should close all other views on the document. It depends on the application what will happen. But for the moment we assume that the view is only closed, and the document stays in memory. Our application has a specific menu that does in fact the same as pressing the window close button.

The following set of actions will be taken to close the view:

After all this the frame was closed, and the document is still in memory. If the closing of the frame would close the last view on the document, and the strategy is to save modified documents when the last view is closed, the a2dDocument::Close( bool force ) would have bin called by the connector class.

closing a document

Closing a document via a menu in a child frame, would require closing this and all other views plus frames which are on this same document.

In other types of applications, where there is only a single frame, the frame and views are often preserved when a document is closed, and they will be reused by a new opened document. Closing a document, will then result in calling a2dView::OnDisConnectView(), which disconnects views from the document via the view its connector.

Again this is just an example on how the closing will take place, there are many ways for the application to handle the close event in a different ways, or to shift certain tasks from the view to the connector or visa versa. but what is explained here is the wxArt2D most likely and maybe best way to do things.

closing the application

We now know how to close a frame/vuew on a document, and we also how to handle clsoing of one document. The last case is closing the complete applicition. We assumen various documents are open, and each document has several view on it, which are displayed in child frames.

So we start with the application its Exit menu, and the rest follows:

What is important

The whole closing procedure, no matter of it comes from a child frame or from the parent frame. It will try to close a view. In that is via a2dView::Close( bool force ). Instead of destroying a frame directly on a close window event, the close window event asks the view first. If the view and the view its connector do agree, the close view event, is sent up the window chain, propagated upwards. Where it eventually will arrive in the frame again. a2dDocumentFrame::OnCloseView() will eventually destroy the frame. The exact thing will happen when all document are closed, which needs to result in all views to close and frames to be destroyed. But there the a2dView::Close() is called by a2dDocument::DisConnectAllViews().
The thing to notice is that the a2dCloseViewEvent which is sent by a2dView::Close() to its m_display window, is propagated in opposite directly to the frame. Normally event like mouse events come from the frame and its subwindows to be redirected to the view, but here it is the other way around.

wxArt2D: ClosingDocviewParentChild (last edited 2009-08-02 22:00:20 by KlaasHolwerda)