-void wxBitmapToggleButton::OnPaint(wxPaintEvent &WXUNUSED(event))
-{
- wxSize size = GetSize();
-
- wxBitmap bitmap = m_bitmap;
-
- wxPaintDC dc(this);
- wxRendererNative &renderer = wxRendererNative::Get();
- int flags = 0;
- if (m_depressed)
- flags |= wxCONTROL_PRESSED;
- wxRect rect(0,0,size.x,size.y);
- renderer.DrawPushButton( this, dc, rect, flags );
-
- if (bitmap.IsOk())
- {
- if (!IsEnabled())
- {
- if (!m_disabledBitmap.IsOk())
- {
- wxImage image = m_bitmap.ConvertToImage();
- m_disabledBitmap = wxBitmap( image.ConvertToGreyscale() );
- }
-
- bitmap = m_disabledBitmap;
- }
-
- wxSize bsize = bitmap.GetSize();
- int offset = 0;
- if (m_depressed) offset = 1;
- dc.DrawBitmap( bitmap, (size.x-bsize.x) / 2 + offset, (size.y-bsize.y) / 2 + offset, true );
- }
-
-}
-
-void wxBitmapToggleButton::OnMouse(wxMouseEvent &event)
-{
- if (!IsEnabled())
- return;
-
- wxSize size = GetSize();
- bool mouse_in = ((event.GetX() > 0) && (event.GetX() < size.x) &&
- (event.GetY() > 0) && (event.GetY() < size.y));
-
- if (m_capturing)
- {
- bool old_depressed = m_depressed;
- if (mouse_in)
- m_depressed = !m_oldValue;
- else
- m_depressed = m_oldValue;
-
- if (event.LeftUp())
- {
- ReleaseCapture();
- m_capturing = false;
- if (mouse_in)
- {
- wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
- event.SetInt(GetValue());
- event.SetEventObject(this);
- ProcessCommand(event);
- }
- }
-
- if (old_depressed != m_depressed)
- Refresh();
- }
- else
- {
- if (event.LeftDown())
- {
- m_capturing = true;
- m_oldValue = m_depressed;
- m_depressed = !m_oldValue;
- CaptureMouse();
- Refresh();
- }
- }
-}
-
-void wxBitmapToggleButton::OnChar(wxKeyEvent &event)
-{
- if (event.GetKeyCode() == WXK_SPACE)
- {
- m_depressed = !m_depressed;
- Refresh();
-
- wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
- event.SetInt(GetValue());
- event.SetEventObject(this);
- ProcessCommand(event);
- }
-}
-
-void wxBitmapToggleButton::OnSize(wxSizeEvent &WXUNUSED(event))
-{
- Refresh();
-}
-
-wxSize wxBitmapToggleButton::DoGetBestSize() const
-{
- if (!m_bitmap.IsOk())
- return wxSize(16,16);
-
- wxSize ret = m_bitmap.GetSize();
- ret.x += 8;
- ret.y += 8;
- return ret;
-}
-