+ m_windowId = vId;
+ lStyle = WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON;
+
+ //
+ // OS/2 PM does not have Right/Left/Top/Bottom styles.
+ // We will have to define an additional style when we implement notebooks
+ // for a notebook page button
+ //
+ if (m_windowStyle & wxCLIP_SIBLINGS )
+ lStyle |= WS_CLIPSIBLINGS;
+
+ m_hWnd = (WXHWND)::WinCreateWindow( GetHwndOf(pParent) // Parent handle
+ ,WC_BUTTON // A Button class window
+ ,sLabel.c_str() // Button text
+ ,lStyle // Button style
+ ,0, 0, 0, 0 // Location and size
+ ,GetHwndOf(pParent) // Owner handle
+ ,HWND_TOP // Top of Z-Order
+ ,vId // Identifier
+ ,NULL // No control data
+ ,NULL // No Presentation parameters
+ );
+ if (m_hWnd == 0)
+ {
+ return false;
+ }
+
+ //
+ // Subclass again for purposes of dialog editing mode
+ //
+ SubclassWin(m_hWnd);
+ wxFont* pButtonFont = new wxFont( 8
+ ,wxSWISS
+ ,wxNORMAL
+ ,wxNORMAL
+ );
+ SetFont(*pButtonFont);
+ SetXComp(0);
+ SetYComp(0);
+ SetSize( rPos.x
+ ,rPos.y
+ ,rSize.x
+ ,rSize.y
+ );
+ delete pButtonFont;
+ return true;
+} // end of wxButton::Create
+
+wxButton::~wxButton()
+{
+ wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+
+ if (tlw)
+ {
+ if (tlw->GetDefaultItem() == this)
+ {
+ //
+ // Don't leave the panel with invalid default item
+ //
+ tlw->SetDefaultItem(NULL);
+ }
+ }
+} // end of wxButton::~wxButton
+
+// ----------------------------------------------------------------------------
+// size management including autosizing
+// ----------------------------------------------------------------------------
+
+wxSize wxButton::DoGetBestSize() const
+{
+ wxString rsLabel = wxGetWindowText(GetHWND());
+ int nWidthButton;
+ int nWidthChar;
+ int nHeightChar;
+ wxFont vFont = (wxFont)GetFont();
+
+ GetTextExtent( rsLabel
+ ,&nWidthButton
+ ,NULL
+ );
+
+ wxGetCharSize( GetHWND()
+ ,&nWidthChar
+ ,&nHeightChar
+ ,&vFont
+ );
+
+ //
+ // 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 += (int)(nHeightChar/1.5);
+
+ if (!HasFlag(wxBU_EXACTFIT))
+ {
+ wxSize vSize = GetDefaultSize();
+
+ if (nWidthButton > vSize.x)
+ vSize.x = nWidthButton;
+ if (nHeightButton > vSize.y)
+ vSize.y = nHeightButton;
+ return vSize;
+ }
+ return wxSize( nWidthButton
+ ,nHeightButton
+ );
+} // 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