47 : wxWindow(parent, id)
48{
49 SetBackgroundColour(*wxWHITE);
50 m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
51 m_label = label;
52 m_image = image;
53 m_imageSize = wxSize(image.GetWidth(), image.GetHeight());
54
55
56 wxScreenDC dc;
57 dc.SetFont(m_font);
58 wxSize textSize = dc.GetTextExtent(label);
59
60 int buttonWidth = 0;
61 if (textSize.GetWidth() > m_imageSize.GetWidth()) {
62 buttonWidth = textSize.GetWidth();
63 m_imagePosition = wxPoint((buttonWidth - m_imageSize.GetWidth()) / 2 + m_borderSize, m_borderSize);
64 m_labelPosition = wxPoint(m_borderSize, m_imageSize.GetHeight() + m_borderSize);
65 }
66 else {
67 buttonWidth = m_imageSize.GetWidth();
68 m_imagePosition = wxPoint(m_borderSize, m_borderSize);
69 m_labelPosition =
70 wxPoint((buttonWidth - textSize.GetWidth()) / 2 + m_borderSize, m_imageSize.GetHeight() + m_borderSize);
71 }
72 m_buttonSize =
73 wxSize(buttonWidth + 2 * m_borderSize, textSize.GetHeight() + m_imageSize.GetHeight() + 2 * m_borderSize);
74 SetMinSize(m_buttonSize + wxSize(m_borderSize, m_borderSize));
75
76
77 Bind(wxEVT_PAINT, &ControlElementButton::OnPaint, this);
78 Bind(wxEVT_ENTER_WINDOW, &ControlElementButton::OnMouseEnter, this);
79 Bind(wxEVT_LEAVE_WINDOW, &ControlElementButton::OnMouseLeave, this);
80 Bind(wxEVT_LEFT_DOWN, &ControlElementButton::OnLeftClickDown, this);
81 Bind(wxEVT_LEFT_UP, &ControlElementButton::OnLeftClickUp, this);
82}