I've tried to design my own flat button control with the following code:
Code: Select all
BEGIN_EVENT_TABLE (CFlatButton, wxPanel)
EVT_PAINT (CFlatButton::OnPaint)
EVT_LEFT_DOWN (CFlatButton::OnLeftClick)
EVT_ENTER_WINDOW (CFlatButton::OnMouseIn)
EVT_LEAVE_WINDOW (CFlatButton::OnMouseOut)
EVT_LEFT_UP (CFlatButton::OnMouseUp)
END_EVENT_TABLE ()
IMPLEMENT_DYNAMIC_CLASS (CFlatButton, wxPanel)
CFlatButton::CFlatButton (wxWindow* parent, wxWindowID id, const wxString& label,
const wxPoint& pos, const wxSize& size, const bool& b_border)
{
wxPanel::Create (parent, id, pos, size, 0, "CFlatButton");
SetLabel (label);
SetFont (parent->GetFont ());
s_label = label;
wxClientDC dc ((wxWindow *) this);
int w_c, h_c;
dc.GetTextExtent (s_label, &w_c, &h_c);
SetSize (w_c + 10, h_c);
i_state = 0; //i_state: 0 = normal; 1 = hover (mouseover); 2 = clicked
}
void CFlatButton::OnLeftClick (wxMouseEvent &event)
{
wxCommandEvent myevent (wxEVT_COMMAND_BUTTON_CLICKED, GetId());
wxPostEvent (this, myevent);
i_state = 2;
Refresh ();
event.Skip ();
}
void CFlatButton::OnMouseIn (wxMouseEvent &event)
{
i_state = 1;
Refresh ();
event.Skip ();
}
void CFlatButton::OnMouseOut (wxMouseEvent &event)
{
i_state = 0;
Refresh ();
event.Skip ();
}
void CFlatButton::OnMouseDown (wxMouseEvent &event)
{
i_state = 2;
Refresh ();
event.Skip ();
}
void CFlatButton::OnMouseUp (wxMouseEvent &event)
{
i_state = 0;
Refresh ();
event.Skip ();
}
void CFlatButton::OnPaint (wxPaintEvent& WXUNUSED (event))
{
// Painting control
// if i_state == 0 - normal design
// if i_state == 1 - bright text colour
// if i_state == 2 - bright background colour
}
When I click the Flatbutton and another dialog is shown, the Flatbutton state stays in pressed mode (because neither OnMouseUp nor OnMouseOut is called).
What can I do to release the button?
Thanks for any help!