2020-09-19 23:41:26 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Ian McInerney <ian.s.mcinerney at ieee dot org>
|
2023-06-03 20:41:56 +00:00
|
|
|
* Copyright (C) 2020-2023 Kicad Developers, see AUTHORS.txt for contributors.
|
2020-09-19 23:41:26 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kiplatform/ui.h>
|
2023-10-22 19:40:05 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/common_settings.h>
|
2020-09-19 23:41:26 +00:00
|
|
|
#include <widgets/bitmap_button.h>
|
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/dcclient.h>
|
|
|
|
#include <wx/renderer.h>
|
|
|
|
#include <wx/settings.h>
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
#define wxCONTROL_SEPARATOR wxCONTROL_SPECIAL
|
|
|
|
|
2020-09-19 23:41:26 +00:00
|
|
|
|
|
|
|
BITMAP_BUTTON::BITMAP_BUTTON( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos,
|
|
|
|
const wxSize& aSize, int aStyles ) :
|
|
|
|
wxPanel( aParent, aId, aPos, aSize, aStyles ),
|
2022-08-19 08:42:47 +00:00
|
|
|
m_isRadioButton( false ),
|
|
|
|
m_showBadge( false ),
|
2023-05-02 10:51:53 +00:00
|
|
|
m_badgeColor( wxColor( 210, 0, 0 ) ), // dark red
|
2022-08-19 08:42:47 +00:00
|
|
|
m_badgeTextColor( wxColor( wxT( "white" ) ) ),
|
|
|
|
m_buttonState( 0 ),
|
|
|
|
m_padding( 0 ),
|
2023-10-22 19:40:05 +00:00
|
|
|
m_isToolbarButton( false ),
|
2023-07-27 02:03:05 +00:00
|
|
|
m_acceptDraggedInClicks( false ),
|
|
|
|
m_centerBitmap( false )
|
2020-09-19 23:41:26 +00:00
|
|
|
{
|
|
|
|
if( aSize == wxDefaultSize )
|
2021-10-12 20:05:37 +00:00
|
|
|
SetMinSize( wxButton::GetDefaultSize() + wxSize( m_padding * 2, m_padding * 2) );
|
|
|
|
|
2022-08-18 20:41:43 +00:00
|
|
|
m_badgeFont = GetFont().Smaller().MakeBold();
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
setupEvents();
|
|
|
|
}
|
2020-09-19 23:41:26 +00:00
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
BITMAP_BUTTON::BITMAP_BUTTON( wxWindow* aParent, wxWindowID aId, const wxBitmap& aDummyBitmap,
|
|
|
|
const wxPoint& aPos, const wxSize& aSize, int aStyles ) :
|
|
|
|
wxPanel( aParent, aId, aPos, aSize, aStyles ),
|
2022-06-12 19:09:21 +00:00
|
|
|
m_isRadioButton( false ),
|
2022-08-19 08:42:47 +00:00
|
|
|
m_showBadge( false ),
|
2023-07-27 02:03:05 +00:00
|
|
|
m_badgeColor( wxColor( 210, 0, 0 ) ), // dark red
|
|
|
|
m_badgeTextColor( wxColor( wxT( "white" ) ) ),
|
2021-10-12 20:05:37 +00:00
|
|
|
m_buttonState( 0 ),
|
|
|
|
m_padding( 5 ),
|
2023-10-22 19:40:05 +00:00
|
|
|
m_isToolbarButton( false ),
|
2023-07-27 02:03:05 +00:00
|
|
|
m_acceptDraggedInClicks( false ),
|
|
|
|
m_centerBitmap( false )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
if( aSize == wxDefaultSize )
|
|
|
|
SetMinSize( wxButton::GetDefaultSize() + wxSize( m_padding * 2, m_padding * 2) );
|
|
|
|
|
2023-07-27 02:03:05 +00:00
|
|
|
m_badgeFont = GetFont().Smaller().MakeBold();
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
setupEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BITMAP_BUTTON::setupEvents()
|
|
|
|
{
|
2020-09-19 23:41:26 +00:00
|
|
|
Bind( wxEVT_PAINT, &BITMAP_BUTTON::OnPaint, this );
|
|
|
|
Bind( wxEVT_LEFT_UP, &BITMAP_BUTTON::OnLeftButtonUp, this );
|
|
|
|
Bind( wxEVT_LEFT_DOWN, &BITMAP_BUTTON::OnLeftButtonDown, this );
|
2021-06-07 18:17:00 +00:00
|
|
|
Bind( wxEVT_LEAVE_WINDOW, &BITMAP_BUTTON::OnMouseLeave, this );
|
|
|
|
Bind( wxEVT_ENTER_WINDOW, &BITMAP_BUTTON::OnMouseEnter, this );
|
|
|
|
Bind( wxEVT_KILL_FOCUS, &BITMAP_BUTTON::OnKillFocus, this );
|
|
|
|
Bind( wxEVT_SET_FOCUS, &BITMAP_BUTTON::OnSetFocus, this );
|
2020-09-19 23:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BITMAP_BUTTON::~BITMAP_BUTTON()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BITMAP_BUTTON::SetPadding( int aPadding )
|
|
|
|
{
|
|
|
|
m_padding = aPadding;
|
2021-10-12 20:05:37 +00:00
|
|
|
SetMinSize( m_unadjustedMinSize + wxSize( aPadding * 2, aPadding * 2 ) );
|
2020-09-19 23:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-03 15:32:36 +00:00
|
|
|
void BITMAP_BUTTON::SetBitmap( const wxBitmapBundle& aBmp )
|
2020-09-19 23:41:26 +00:00
|
|
|
{
|
|
|
|
m_normalBitmap = aBmp;
|
2023-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
// This is a bit of a hack, but fixes button scaling issues on some platforms when those buttons
|
|
|
|
// use KiScaledBitmap. When that method is retired, this can probably be revisited.
|
|
|
|
if( m_isToolbarButton )
|
|
|
|
{
|
|
|
|
m_unadjustedMinSize = m_normalBitmap.GetPreferredBitmapSizeFor( this );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifndef __WXMSW__
|
|
|
|
m_unadjustedMinSize = m_normalBitmap.GetDefaultSize();
|
|
|
|
#else
|
|
|
|
m_unadjustedMinSize = m_normalBitmap.GetPreferredBitmapSizeFor( this );
|
|
|
|
#endif
|
|
|
|
}
|
2020-09-19 23:41:26 +00:00
|
|
|
|
2023-06-03 15:32:36 +00:00
|
|
|
SetMinSize( wxSize( m_unadjustedMinSize.GetWidth() + ( m_padding * 2 ),
|
|
|
|
m_unadjustedMinSize.GetHeight() + ( m_padding * 2 ) ) );
|
2020-09-19 23:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-03 15:32:36 +00:00
|
|
|
void BITMAP_BUTTON::SetDisabledBitmap( const wxBitmapBundle& aBmp )
|
2020-09-19 23:41:26 +00:00
|
|
|
{
|
|
|
|
m_disabledBitmap = aBmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-07 18:17:00 +00:00
|
|
|
void BITMAP_BUTTON::AcceptDragInAsClick( bool aAcceptDragIn )
|
2020-09-19 23:41:26 +00:00
|
|
|
{
|
2021-06-07 18:17:00 +00:00
|
|
|
m_acceptDraggedInClicks = aAcceptDragIn;
|
|
|
|
}
|
|
|
|
|
2020-09-19 23:41:26 +00:00
|
|
|
|
2021-06-07 18:17:00 +00:00
|
|
|
void BITMAP_BUTTON::OnMouseLeave( wxEvent& aEvent )
|
|
|
|
{
|
2022-12-27 23:55:09 +00:00
|
|
|
if( hasFlag( wxCONTROL_CURRENT | wxCONTROL_PRESSED ) )
|
|
|
|
{
|
|
|
|
clearFlag( wxCONTROL_CURRENT | wxCONTROL_PRESSED );
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
2020-09-19 23:41:26 +00:00
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-07 18:17:00 +00:00
|
|
|
void BITMAP_BUTTON::OnMouseEnter( wxEvent& aEvent )
|
2020-09-19 23:41:26 +00:00
|
|
|
{
|
2022-12-27 23:55:09 +00:00
|
|
|
if( !hasFlag( wxCONTROL_CURRENT ) )
|
|
|
|
{
|
|
|
|
setFlag( wxCONTROL_CURRENT );
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:17:00 +00:00
|
|
|
aEvent.Skip();
|
|
|
|
}
|
2020-09-19 23:41:26 +00:00
|
|
|
|
2021-06-07 18:17:00 +00:00
|
|
|
|
|
|
|
void BITMAP_BUTTON::OnKillFocus( wxEvent& aEvent )
|
|
|
|
{
|
2023-07-27 02:03:05 +00:00
|
|
|
if( hasFlag( wxCONTROL_FOCUSED | wxCONTROL_CURRENT | wxCONTROL_PRESSED | wxCONTROL_SELECTED ) )
|
2022-12-27 23:55:09 +00:00
|
|
|
{
|
2023-07-27 02:03:05 +00:00
|
|
|
clearFlag( wxCONTROL_FOCUSED | wxCONTROL_CURRENT | wxCONTROL_PRESSED | wxCONTROL_SELECTED );
|
2022-12-27 23:55:09 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:17:00 +00:00
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BITMAP_BUTTON::OnSetFocus( wxEvent& aEvent )
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
if( !hasFlag( wxCONTROL_CHECKABLE ) )
|
2022-12-27 23:55:09 +00:00
|
|
|
{
|
|
|
|
if( !hasFlag( wxCONTROL_FOCUSED ) )
|
|
|
|
{
|
|
|
|
setFlag( wxCONTROL_FOCUSED );
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2020-09-19 23:41:26 +00:00
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BITMAP_BUTTON::OnLeftButtonUp( wxMouseEvent& aEvent )
|
|
|
|
{
|
|
|
|
// Only create a button event when the control is enabled
|
2021-06-07 18:17:00 +00:00
|
|
|
// and only accept clicks that came without prior mouse-down if configured
|
2021-10-12 20:05:37 +00:00
|
|
|
if( !hasFlag( wxCONTROL_DISABLED )
|
|
|
|
&& ( m_acceptDraggedInClicks || hasFlag( wxCONTROL_PRESSED | wxCONTROL_FOCUSED ) ) )
|
2020-09-19 23:41:26 +00:00
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
GetEventHandler()->CallAfter( [=]()
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( wxEVT_BUTTON, GetId() );
|
|
|
|
evt.SetEventObject( this );
|
|
|
|
GetEventHandler()->ProcessEvent( evt );
|
|
|
|
} );
|
2020-09-19 23:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clearFlag( wxCONTROL_PRESSED );
|
|
|
|
Refresh();
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BITMAP_BUTTON::OnLeftButtonDown( wxMouseEvent& aEvent )
|
|
|
|
{
|
2021-10-12 20:05:37 +00:00
|
|
|
if( hasFlag( wxCONTROL_CHECKABLE ) )
|
|
|
|
{
|
2022-06-12 19:09:21 +00:00
|
|
|
if( hasFlag( wxCONTROL_CHECKED ) && !m_isRadioButton )
|
2021-10-12 20:05:37 +00:00
|
|
|
{
|
|
|
|
clearFlag( wxCONTROL_CHECKED );
|
2022-01-03 01:20:25 +00:00
|
|
|
|
|
|
|
GetEventHandler()->CallAfter(
|
|
|
|
[=]()
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( wxEVT_BUTTON, GetId() );
|
|
|
|
evt.SetEventObject( this );
|
|
|
|
evt.SetInt( 0 );
|
|
|
|
GetEventHandler()->ProcessEvent( evt );
|
|
|
|
} );
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setFlag( wxCONTROL_CHECKED );
|
|
|
|
|
2022-01-03 01:20:25 +00:00
|
|
|
GetEventHandler()->CallAfter(
|
|
|
|
[=]()
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( wxEVT_BUTTON, GetId() );
|
|
|
|
evt.SetEventObject( this );
|
|
|
|
evt.SetInt( 1 );
|
|
|
|
GetEventHandler()->ProcessEvent( evt );
|
|
|
|
} );
|
2021-10-12 20:05:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setFlag( wxCONTROL_PRESSED );
|
|
|
|
}
|
|
|
|
|
2020-09-19 23:41:26 +00:00
|
|
|
Refresh();
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BITMAP_BUTTON::OnPaint( wxPaintEvent& aEvent )
|
|
|
|
{
|
|
|
|
bool darkMode = KIPLATFORM::UI::IsDarkTheme();
|
|
|
|
wxColor highlightColor = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT );
|
|
|
|
|
|
|
|
// The drawing rectangle
|
|
|
|
wxRect rect( wxPoint( 0, 0 ), GetSize() );
|
|
|
|
wxPaintDC dc( this );
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
if( hasFlag( wxCONTROL_SEPARATOR ) )
|
|
|
|
{
|
|
|
|
dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) ) );
|
|
|
|
dc.DrawLine( wxPoint( GetSize().x / 2, 0 ), wxPoint( GetSize().x / 2, GetSize().y ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-19 23:41:26 +00:00
|
|
|
// This drawing is done so the button looks the same as an AUI toolbar button
|
|
|
|
if( !hasFlag( wxCONTROL_DISABLED ) )
|
|
|
|
{
|
|
|
|
if( hasFlag( wxCONTROL_PRESSED ) )
|
|
|
|
{
|
|
|
|
dc.SetPen( wxPen( highlightColor ) );
|
|
|
|
dc.SetBrush( wxBrush( highlightColor.ChangeLightness( darkMode ? 20 : 150 ) ) );
|
|
|
|
dc.DrawRectangle( rect );
|
|
|
|
}
|
2021-06-07 18:17:00 +00:00
|
|
|
else if( hasFlag( wxCONTROL_CURRENT | wxCONTROL_FOCUSED ) )
|
2020-09-19 23:41:26 +00:00
|
|
|
{
|
|
|
|
dc.SetPen( wxPen( highlightColor ) );
|
|
|
|
dc.SetBrush( wxBrush( highlightColor.ChangeLightness( darkMode ? 40 : 170 ) ) );
|
|
|
|
|
|
|
|
// Checked items need a lighter hover rectangle
|
|
|
|
if( hasFlag( wxCONTROL_CHECKED ) )
|
|
|
|
dc.SetBrush( wxBrush( highlightColor.ChangeLightness( darkMode ? 50 : 180 ) ) );
|
|
|
|
|
|
|
|
dc.DrawRectangle( rect );
|
|
|
|
}
|
|
|
|
else if( hasFlag( wxCONTROL_CHECKED ) )
|
|
|
|
{
|
|
|
|
dc.SetPen( wxPen( highlightColor ) );
|
|
|
|
dc.SetBrush( wxBrush( highlightColor.ChangeLightness( darkMode ? 40 : 170 ) ) );
|
|
|
|
dc.DrawRectangle( rect );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-03 15:32:36 +00:00
|
|
|
const wxBitmapBundle& bmp = hasFlag( wxCONTROL_DISABLED ) ? m_disabledBitmap : m_normalBitmap;
|
2020-09-19 23:41:26 +00:00
|
|
|
|
2023-07-27 02:03:05 +00:00
|
|
|
wxPoint drawBmpPos( m_padding, m_padding );
|
2023-10-22 19:40:05 +00:00
|
|
|
wxBitmap bmpImg;
|
|
|
|
double scale = KIPLATFORM::UI::GetPixelScaleFactor( this );
|
|
|
|
int size;
|
|
|
|
wxSize bmSize;
|
|
|
|
|
|
|
|
if( m_isToolbarButton )
|
|
|
|
{
|
|
|
|
size = Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size;
|
|
|
|
bmSize = wxSize( size, size );
|
|
|
|
bmpImg = bmp.GetBitmap( bmSize * scale );
|
|
|
|
|
|
|
|
// wxBitmapBundle::GetBitmap thinks we need this rescaled to match the base size
|
|
|
|
if( bmpImg.IsOk() )
|
|
|
|
bmpImg.SetScaleFactor( scale );
|
|
|
|
}
|
2023-10-23 17:02:22 +00:00
|
|
|
else if( bmp.IsOk() )
|
2023-10-22 19:40:05 +00:00
|
|
|
{
|
|
|
|
bmpImg = bmp.GetBitmapFor( this );
|
|
|
|
bmSize = bmpImg.GetSize();
|
|
|
|
}
|
|
|
|
|
2023-07-27 02:03:05 +00:00
|
|
|
if( m_centerBitmap )
|
|
|
|
{
|
2023-08-06 17:53:34 +00:00
|
|
|
// dont let it go negative if bmp is larger than the button
|
2023-10-22 19:40:05 +00:00
|
|
|
int x = std::max( ( rect.width - bmSize.x ) / 2, 0 );
|
|
|
|
int y = std::max( ( rect.height - bmSize.y ) / 2, 0 );
|
2023-08-06 17:53:34 +00:00
|
|
|
drawBmpPos = wxPoint( x, y );
|
2023-07-27 02:03:05 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 23:41:26 +00:00
|
|
|
// Draw the bitmap with the upper-left corner offset by the padding
|
|
|
|
if( bmp.IsOk() )
|
2023-07-27 02:03:05 +00:00
|
|
|
dc.DrawBitmap( bmpImg, drawBmpPos, true );
|
2022-08-18 20:41:43 +00:00
|
|
|
|
|
|
|
// Draw the badge
|
|
|
|
if( m_showBadge )
|
|
|
|
{
|
|
|
|
dc.SetFont( m_badgeFont );
|
|
|
|
|
2023-07-27 02:03:05 +00:00
|
|
|
wxSize box_size = dc.GetTextExtent( m_badgeText );
|
|
|
|
wxSize box_offset = box_size;
|
|
|
|
wxSize text_offset = box_offset;
|
|
|
|
if( m_padding != 0 )
|
|
|
|
{
|
|
|
|
box_offset += wxSize( m_padding - 2, m_padding );
|
|
|
|
text_offset -= wxSize( 3, 1 );
|
|
|
|
}
|
2022-08-18 20:41:43 +00:00
|
|
|
|
|
|
|
dc.SetPen( wxPen( m_badgeColor ) );
|
|
|
|
dc.SetBrush( wxBrush( m_badgeColor ) );
|
|
|
|
dc.DrawRoundedRectangle( rect.GetRightBottom() - box_offset, box_size, -0.25 );
|
|
|
|
|
|
|
|
dc.SetTextForeground( m_badgeTextColor );
|
|
|
|
dc.DrawText( m_badgeText, rect.GetRightBottom() - text_offset );
|
|
|
|
}
|
2020-09-19 23:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BITMAP_BUTTON::Enable( bool aEnable )
|
|
|
|
{
|
|
|
|
// If the requested state is already the current state, don't do anything
|
|
|
|
if( aEnable != hasFlag( wxCONTROL_DISABLED ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxPanel::Enable( aEnable );
|
|
|
|
|
2022-12-27 23:55:09 +00:00
|
|
|
if( aEnable && hasFlag( wxCONTROL_DISABLED ) )
|
|
|
|
{
|
2020-09-19 23:41:26 +00:00
|
|
|
clearFlag( wxCONTROL_DISABLED );
|
2022-12-27 23:55:09 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
2020-09-19 23:41:26 +00:00
|
|
|
|
2022-12-27 23:55:09 +00:00
|
|
|
if( !aEnable && !hasFlag( wxCONTROL_DISABLED ) )
|
|
|
|
{
|
|
|
|
setFlag( wxCONTROL_DISABLED );
|
|
|
|
Refresh();
|
|
|
|
}
|
2020-09-19 23:41:26 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
void BITMAP_BUTTON::SetIsCheckButton()
|
|
|
|
{
|
|
|
|
setFlag( wxCONTROL_CHECKABLE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-12 19:09:21 +00:00
|
|
|
void BITMAP_BUTTON::SetIsRadioButton()
|
|
|
|
{
|
|
|
|
setFlag( wxCONTROL_CHECKABLE );
|
|
|
|
m_isRadioButton = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-12 20:05:37 +00:00
|
|
|
void BITMAP_BUTTON::SetIsSeparator()
|
|
|
|
{
|
|
|
|
setFlag( wxCONTROL_SEPARATOR | wxCONTROL_DISABLED );
|
|
|
|
SetMinSize( wxSize( m_padding * 2, wxButton::GetDefaultSize().y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-19 23:41:26 +00:00
|
|
|
void BITMAP_BUTTON::Check( bool aCheck )
|
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxASSERT_MSG( hasFlag( wxCONTROL_CHECKABLE ), wxS( "Button is not a checkButton." ) );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
2022-12-27 23:55:09 +00:00
|
|
|
if( aCheck && !hasFlag( wxCONTROL_CHECKED ) )
|
|
|
|
{
|
2020-09-19 23:41:26 +00:00
|
|
|
setFlag( wxCONTROL_CHECKED );
|
2022-12-27 23:55:09 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
2020-09-19 23:41:26 +00:00
|
|
|
|
2022-12-27 23:55:09 +00:00
|
|
|
if( !aCheck && hasFlag( wxCONTROL_CHECKED ) )
|
|
|
|
{
|
|
|
|
clearFlag( wxCONTROL_CHECKED );
|
|
|
|
Refresh();
|
|
|
|
}
|
2020-09-19 23:41:26 +00:00
|
|
|
}
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool BITMAP_BUTTON::IsChecked() const
|
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxASSERT_MSG( hasFlag( wxCONTROL_CHECKABLE ), wxS( "Button is not a checkButton." ) );
|
2021-10-12 20:05:37 +00:00
|
|
|
|
|
|
|
return hasFlag( wxCONTROL_CHECKED );
|
2023-06-09 12:58:52 +00:00
|
|
|
}
|