+ // buttons never have an external border, they draw their own one
+ WXDWORD msStyle = wxControl::MSWGetStyle
+ (
+ (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle
+ );
+
+ // we must use WS_CLIPSIBLINGS with the buttons or they would draw over
+ // each other in any resizable dialog which has more than one button in
+ // the bottom
+ msStyle |= WS_CLIPSIBLINGS;
+
+ // don't use "else if" here: weird as it is, but you may combine wxBU_LEFT
+ // and wxBU_RIGHT to get BS_CENTER!
+ if ( style & wxBU_LEFT )
+ msStyle |= BS_LEFT;
+ if ( style & wxBU_RIGHT )
+ msStyle |= BS_RIGHT;
+ if ( style & wxBU_TOP )
+ msStyle |= BS_TOP;
+ if ( style & wxBU_BOTTOM )
+ msStyle |= BS_BOTTOM;
+#ifndef __WXWINCE__
+ // flat 2d buttons
+ if ( style & wxNO_BORDER )
+ msStyle |= BS_FLAT;
+#endif // __WXWINCE__
+
+ return msStyle;
+}
+
+/* static */
+wxSize wxButtonBase::GetDefaultSize()
+{
+ static wxSize s_sizeBtn;
+
+ if ( s_sizeBtn.x == 0 )
+ {
+ wxScreenDC dc;
+ dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
+
+ // The size of a standard button in the dialog units is 50x14,
+ // translate this to pixels.
+ //
+ // Windows' computes dialog units using average character width over
+ // upper- and lower-case ASCII alphabet and not using the average
+ // character width metadata stored in the font; see
+ // http://support.microsoft.com/default.aspx/kb/145994 for detailed
+ // discussion.
+ //
+ // NB: wxMulDivInt32() is used, because it correctly rounds the result
+
+ const wxSize base = wxPrivate::GetAverageASCIILetterSize(dc);
+ s_sizeBtn.x = wxMulDivInt32(50, base.x, 4);
+ s_sizeBtn.y = wxMulDivInt32(14, base.y, 8);
+ }
+
+ return s_sizeBtn;
+}
+
+// ----------------------------------------------------------------------------
+// default button handling
+// ----------------------------------------------------------------------------
+
+/*
+ The comment below and all this code is probably due to not using WM_NEXTDLGCTL
+ message when changing focus (but just SetFocus() which is not enough), see
+ http://blogs.msdn.com/oldnewthing/archive/2004/08/02/205624.aspx for the
+ full explanation.
+
+ TODO: Do use WM_NEXTDLGCTL and get rid of all this code.
+
+
+ "Everything you ever wanted to know about the default buttons" or "Why do we
+ have to do all this?"
+
+ 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.
+
+ NB: all this is quite complicated by now and the worst is that normally
+ it shouldn't be necessary at all as for the normal Windows programs
+ DefWindowProc() and IsDialogMessage() take care of all this
+ automatically -- however in wxWidgets programs this doesn't work for
+ nested hierarchies (i.e. a notebook inside a notebook) for unknown
+ reason and so we have to reproduce all this code ourselves. It would be
+ very nice if we could avoid doing it.
+ */
+
+// 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;