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