| 42 | #include <wx/tglbtn.h> |
| 43 | |
| 44 | ToggleBitmap::ToggleBitmap(wxWindow *parent, agi::Context *context, const char *cmd_name, int icon_size, const char *ht_ctx, wxSize const& size) |
| 45 | : wxControl(parent, -1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER) |
| 46 | , context(context) |
| 47 | , command(*cmd::get(cmd_name)) |
| 48 | , img(command.Icon(icon_size)) |
| 49 | { |
| 50 | int w = size.GetWidth() != -1 ? size.GetWidth() : img.GetWidth(); |
| 51 | int h = size.GetHeight() != -1 ? size.GetHeight() : img.GetHeight(); |
| 52 | SetClientSize(w, h); |
| 53 | GetSize(&w, &h); |
| 54 | SetSizeHints(w, h, w, h); |
| 55 | |
| 56 | SetBackgroundStyle(wxBG_STYLE_PAINT); |
| 57 | |
| 58 | ToolTipManager::Bind(this, command.StrHelp(), ht_ctx, cmd_name); |
| 59 | Bind(wxEVT_PAINT, &ToggleBitmap::OnPaint, this); |
| 60 | Bind(wxEVT_LEFT_DOWN, &ToggleBitmap::OnMouseEvent, this); |
| 61 | } |
| 62 | |
| 63 | void ToggleBitmap::OnMouseEvent(wxMouseEvent &) { |
| 64 | if (command.Validate(context)) |