]> git.saurik.com Git - wxWidgets.git/blame - docs/doxygen/overviews/windowdeletion.h
fix the @section tag
[wxWidgets.git] / docs / doxygen / overviews / windowdeletion.h
CommitLineData
15b6757b 1/////////////////////////////////////////////////////////////////////////////
3863c5eb 2// Name: windowdeletion.h
15b6757b
FM
3// Purpose: topic overview
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/*!
36c9828f 10
3863c5eb 11@page overview_windowdeletion Window Deletion Overview
36c9828f 12
3863c5eb
BP
13Classes: wxCloseEvent, wxWindow
14
15Window deletion can be a confusing subject, so this overview is provided to
16help make it clear when and how you delete windows, or respond to user requests
17to close windows.
18
19
20@section overview_windowdeletion_sequence Sequence of Events During Window Deletion
21
22When the user clicks on the system close button or system close command, in a
23frame or a dialog, wxWidgets calls wxWindow::Close. This in turn generates an
24EVT_CLOSE event: see wxCloseEvent.
25
26It is the duty of the application to define a suitable event handler, and
27decide whether or not to destroy the window. If the application is for some
28reason forcing the application to close (wxCloseEvent::CanVeto returns @false),
29the window should always be destroyed, otherwise there is the option to ignore
30the request, or maybe wait until the user has answered a question before
31deciding whether it is safe to close. The handler for EVT_CLOSE should signal
32to the calling code if it does not destroy the window, by calling
33wxCloseEvent::Veto. Calling this provides useful information to the calling
34code.
35
36The wxCloseEvent handler should only call wxWindow::Destroy to delete the
37window, and not use the @c delete operator. This is because for some window
38classes, wxWidgets delays actual deletion of the window until all events have
39been processed, since otherwise there is the danger that events will be sent to
40a non-existent window.
41
42As reinforced in the next section, calling Close does not guarantee that the window
43will be destroyed. Call wxWindow::Destroy if you want to be
44certain that the window is destroyed.
45
46
47@section overview_windowdeletion_close Closing Windows
48
49Your application can either use wxWindow::Close event just as the framework
50does, or it can call wxWindow::Destroy directly. If using Close(), you can pass
51a @true argument to this function to tell the event handler that we definitely
52want to delete the frame and it cannot be vetoed.
53
54The advantage of using Close instead of Destroy is that it will call any
55clean-up code defined by the EVT_CLOSE handler; for example it may close a
56document contained in a window after first asking the user whether the work
57should be saved. Close can be vetoed by this process (return @false), whereas
58Destroy definitely destroys the window.
59
60
61@section overview_windowdeletion_default Default Window Close Behaviour
62
63The default close event handler for wxDialog simulates a Cancel command,
64generating a wxID_CANCEL event. Since the handler for this cancel event might
65itself call Close, there is a check for infinite looping. The default handler
66for wxID_CANCEL hides the dialog (if modeless) or calls EndModal(wxID_CANCEL)
67(if modal). In other words, by default, the dialog @e is not destroyed (it
68might have been created on the stack, so the assumption of dynamic creation
69cannot be made).
70
71The default close event handler for wxFrame destroys the frame using Destroy().
72
73
74@section overview_windowdeletion_menuexit User Calls to Exit From a Menu
75
76What should I do when the user calls up Exit from a menu? You can simply call
77wxWindow::Close on the frame. This will invoke your own close event handler
78which may destroy the frame.
79
80You can do checking to see if your application can be safely exited at this
81point, either from within your close event handler, or from within your exit
82menu command handler. For example, you may wish to check that all files have
83been saved. Give the user a chance to save and quit, to not save but quit
84anyway, or to cancel the exit command altogether.
85
86
87@section overview_windowdeletion_exitapp Exiting the Application Gracefully
88
89A wxWidgets application automatically exits when the last top level window
90(wxFrame or wxDialog), is destroyed. Put any application-wide cleanup code in
91wxApp::OnExit (this is a virtual function, not an event handler).
92
93
94@section overview_windowdeletion_deletion Automatic Deletion of Child Windows
95
96Child windows are deleted from within the parent destructor. This includes any
97children that are themselves frames or dialogs, so you may wish to close these
98child frame or dialog windows explicitly from within the parent close handler.
99
100
101@section overview_windowdeletion_windowkinds Other Kinds of Windows
102
103So far we've been talking about 'managed' windows, i.e. frames and dialogs.
104Windows with parents, such as controls, don't have delayed destruction and
105don't usually have close event handlers, though you can implement them if you
106wish. For consistency, continue to use the wxWindow::Destroy function instead
107of the @c delete operator when deleting these kinds of windows explicitly.
108
109*/
36c9828f 110