+ wxPanel* pPanel = wxDynamicCast(GetParent(), wxPanel);
+
+ if (pPanel)
+ {
+ if (pPanel->GetDefaultItem() == this)
+ {
+ //
+ // Don't leave the panel with invalid default item
+ //
+ pPanel->SetDefaultItem(NULL);
+ }
+ }
+} // end of wxButton::~wxButton
+
+// ----------------------------------------------------------------------------
+// size management including autosizing
+// ----------------------------------------------------------------------------
+
+wxSize wxButton::DoGetBestSize() const
+{
+ wxString rsLabel = wxGetWindowText(GetHWND());
+ int nWidthButton;
+ int nWidthChar;
+ int nHeightChar;
+
+ GetTextExtent( rsLabel
+ ,&nWidthButton
+ ,NULL
+ );
+
+ wxGetCharSize( GetHWND()
+ ,&nWidthChar
+ ,&nHeightChar
+ ,(wxFont*)&GetFont()
+ );
+
+ //
+ // Add a margin - the button is wider than just its label
+ //
+ nWidthButton += 3 * nWidthChar;
+
+ //
+ // The button height is proportional to the height of the font used
+ //
+ int nHeightButton = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(nHeightChar);
+
+ //
+ // Need a little extra to make it look right
+ //
+ nHeightButton += nHeightChar/1.5;
+
+ wxSize vSize = GetDefaultSize();
+
+ if (nWidthButton > vSize.x)
+ vSize.x = nWidthButton;
+ if (nHeightButton > vSize.y)
+ vSize.y = nHeightButton;
+ return vSize;
+} // end of wxButton::DoGetBestSize
+
+/* static */
+wxSize wxButton::GetDefaultSize()
+{
+ static wxSize vSizeBtn;
+
+ if (vSizeBtn.x == 0)
+ {
+ wxScreenDC vDc;
+
+ vDc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
+
+ //
+ // The size of a standard button in the dialog units is 50x14,
+ // translate this to pixels
+ // NB1: the multipliers come from the Windows convention
+ // NB2: the extra +1/+2 were needed to get the size be the same as the
+ // size of the buttons in the standard dialog - I don't know how
+ // this happens, but on my system this size is 75x23 in pixels and
+ // 23*8 isn't even divisible by 14... Would be nice to understand
+ // why these constants are needed though!
+ vSizeBtn.x = (50 * (vDc.GetCharWidth() + 1))/4;
+ vSizeBtn.y = ((14 * vDc.GetCharHeight()) + 2)/8;
+ }
+ return vSizeBtn;
+} // end of wxButton::GetDefaultSize
+
+void wxButton::Command (
+ wxCommandEvent& rEvent
+)
+{
+ ProcessCommand (rEvent);
+} // end of wxButton::Command
+
+// ----------------------------------------------------------------------------
+// helpers
+// ----------------------------------------------------------------------------
+
+bool wxButton::SendClickEvent()
+{
+ wxCommandEvent vEvent( wxEVT_COMMAND_BUTTON_CLICKED
+ ,GetId()
+ );
+
+ vEvent.SetEventObject(this);
+ return ProcessCommand(vEvent);
+} // end of wxButton::SendClickEvent