+/*
+ In normal Windows programs there is no need to handle default button
+ manually because this is taken care by the system provided you use
+ WM_NEXTDLGCTL and not just SetFocus() to switch focus betweeh the controls
+ (see http://blogs.msdn.com/oldnewthing/archive/2004/08/02/205624.aspx for
+ the full explanation why just calling SetFocus() is not enough).
+
+ However this only works if the window is a dialog, i.e. uses DefDlgProc(),
+ but not with plain windows using DefWindowProc() and we do want to have
+ default buttons inside frames as well, so we're forced to reimplement all
+ this logic ourselves. It would be great to avoid having to do this but using
+ DefDlgProc() for all the windows would almost certainly result in more
+ problems, we'd need to carefully filter messages and pass some of them to
+ DefWindowProc() and some of them to DefDlgProc() which looks dangerous (what
+ if the handling of some message changes in some Windows version?), so doing
+ this ourselves is probably a lesser evil.
+
+ Read the rest to learn everything you ever wanted to know about the default
+ buttons but were afraid to ask.
+
+
+ In MSW the default button should be activated when the user presses Enter
+ and the current control doesn't process Enter itself somehow. This is
+ handled by ::DefWindowProc() (or maybe ::DefDialogProc()) using DM_SETDEFID
+ Another aspect of "defaultness" is that the default button has different
+ appearance: this is due to BS_DEFPUSHBUTTON style which is completely
+ separate from DM_SETDEFID stuff (!). Also note that BS_DEFPUSHBUTTON should
+ be unset if our parent window is not active so it should be unset whenever
+ we lose activation and set back when we regain it.
+
+ Final complication is that when a button is active, it should be the default
+ one, i.e. pressing Enter on a button always activates it and not another
+ one.
+
+ We handle this by maintaining a permanent and a temporary default items in
+ wxControlContainer (both may be NULL). When a button becomes the current
+ control (i.e. gets focus) it sets itself as the temporary default which
+ ensures that it has the right appearance and that Enter will be redirected
+ to it. When the button loses focus, it unsets the temporary default and so
+ the default item will be the permanent default -- that is the default button
+ if any had been set or none otherwise, which is just what we want.
+ */
+
+// set this button as the (permanently) default one in its panel
+wxWindow *wxButton::SetDefault()
+{
+ // set this one as the default button both for wxWidgets ...
+ wxWindow *winOldDefault = wxButtonBase::SetDefault();
+
+ // ... and Windows
+ SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), false);
+ SetDefaultStyle(this, true);
+
+ return winOldDefault;
+}
+
+// return the top level parent window if it's not being deleted yet, otherwise
+// return NULL
+static wxTopLevelWindow *GetTLWParentIfNotBeingDeleted(wxWindow *win)