KiCad PCB EDA Suite
SPLIT_BUTTON Class Reference

#include <split_button.h>

Inheritance diagram for SPLIT_BUTTON:

Public Member Functions

 SPLIT_BUTTON (wxWindow *aParent, wxWindowID aId, const wxString &aLabel, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize)
 
 ~SPLIT_BUTTON ()
 
wxMenu * GetSplitButtonMenu ()
 
void SetBitmap (const wxBitmap &aBmp)
 
void SetMinSize (const wxSize &aSize) override
 
void SetWidthPadding (int aPadding)
 

Protected Member Functions

void OnKillFocus (wxFocusEvent &aEvent)
 
void OnMouseLeave (wxMouseEvent &aEvent)
 
void OnMouseEnter (wxMouseEvent &aEvent)
 
void OnLeftButtonUp (wxMouseEvent &aEvent)
 
void OnLeftButtonDown (wxMouseEvent &aEvent)
 
void OnPaint (wxPaintEvent &WXUNUSED(aEvent))
 
bool Enable (bool aEnable=true) override
 

Private Attributes

int m_stateButton = 0
 
int m_stateMenu = 0
 
bool m_bIsEnable = true
 
wxColor m_colorNormal
 
wxColor m_colorDisabled
 
const int m_arrowButtonWidth = 20
 
int m_widthPadding = 20
 
bool m_bLButtonDown = false
 
wxString m_label
 
wxMenu * m_pMenu = nullptr
 
wxBitmap m_bitmap
 
wxSize m_unadjustedMinSize
 

Detailed Description

Definition at line 34 of file split_button.h.

Constructor & Destructor Documentation

◆ SPLIT_BUTTON()

SPLIT_BUTTON::SPLIT_BUTTON ( wxWindow *  aParent,
wxWindowID  aId,
const wxString &  aLabel,
const wxPoint &  aPos = wxDefaultPosition,
const wxSize &  aSize = wxDefaultSize 
)

Definition at line 34 of file split_button.cpp.

35  :
36  wxPanel( aParent, aId, aPos, aSize, wxBORDER_NONE | wxTAB_TRAVERSAL, "DropDownButton" ),
37  m_label( aLabel )
38 {
39  m_colorNormal = GetForegroundColour();
40  m_colorDisabled = GetForegroundColour().MakeDisabled();
41 
42  if( aSize == wxDefaultSize )
43  {
44  wxSize defaultSize = wxButton::GetDefaultSize();
45 
46  wxSize textSize = GetTextExtent( m_label );
47  SetMinSize( wxSize( textSize.GetWidth(), defaultSize.GetHeight() ) );
48  }
49 
50  Bind( wxEVT_PAINT, &SPLIT_BUTTON::OnPaint, this );
51  Bind( wxEVT_LEFT_UP, &SPLIT_BUTTON::OnLeftButtonUp, this );
52  Bind( wxEVT_LEFT_DOWN, &SPLIT_BUTTON::OnLeftButtonDown, this );
53  Bind( wxEVT_KILL_FOCUS, &SPLIT_BUTTON::OnKillFocus, this );
54  Bind( wxEVT_LEAVE_WINDOW, &SPLIT_BUTTON::OnMouseLeave, this );
55  Bind( wxEVT_ENTER_WINDOW, &SPLIT_BUTTON::OnMouseEnter, this );
56 
57  m_pMenu = new wxMenu();
58 }
void OnPaint(wxPaintEvent &WXUNUSED(aEvent))
void SetMinSize(const wxSize &aSize) override
void OnKillFocus(wxFocusEvent &aEvent)
void OnLeftButtonUp(wxMouseEvent &aEvent)
void OnMouseLeave(wxMouseEvent &aEvent)
void OnLeftButtonDown(wxMouseEvent &aEvent)
static const wxSize defaultSize(FRAME_T aFrameType)
wxColor m_colorNormal
Definition: split_button.h:61
wxMenu * m_pMenu
Definition: split_button.h:67
wxString m_label
Definition: split_button.h:66
void OnMouseEnter(wxMouseEvent &aEvent)
wxColor m_colorDisabled
Definition: split_button.h:62

References defaultSize(), m_colorDisabled, m_colorNormal, m_label, m_pMenu, OnKillFocus(), OnLeftButtonDown(), OnLeftButtonUp(), OnMouseEnter(), OnMouseLeave(), OnPaint(), and SetMinSize().

◆ ~SPLIT_BUTTON()

SPLIT_BUTTON::~SPLIT_BUTTON ( )

Definition at line 61 of file split_button.cpp.

62 {
63  delete m_pMenu;
64  m_pMenu = nullptr;
65 }
wxMenu * m_pMenu
Definition: split_button.h:67

References m_pMenu.

Member Function Documentation

◆ Enable()

bool SPLIT_BUTTON::Enable ( bool  aEnable = true)
overrideprotected

Definition at line 240 of file split_button.cpp.

241 {
242  m_bIsEnable = aEnable;
243  wxPanel::Enable( m_bIsEnable );
244 
245  if( m_bIsEnable )
246  {
247  m_stateButton = 0;
248  m_stateMenu = 0;
249  }
250  else
251  {
252  m_stateButton = wxCONTROL_DISABLED;
253  m_stateMenu = wxCONTROL_DISABLED;
254  }
255 
256  Refresh();
257 
258  return aEnable;
259 }
bool m_bIsEnable
Definition: split_button.h:60
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...

References m_bIsEnable, m_stateButton, m_stateMenu, and Refresh().

◆ GetSplitButtonMenu()

wxMenu * SPLIT_BUTTON::GetSplitButtonMenu ( )

Definition at line 91 of file split_button.cpp.

92 {
93  return m_pMenu;
94 }
wxMenu * m_pMenu
Definition: split_button.h:67

References m_pMenu.

Referenced by PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE().

◆ OnKillFocus()

void SPLIT_BUTTON::OnKillFocus ( wxFocusEvent &  aEvent)
protected

Definition at line 97 of file split_button.cpp.

98 {
99  m_stateButton = wxCONTROL_CURRENT;
100  m_stateMenu = wxCONTROL_CURRENT;
101  Refresh();
102 
103  aEvent.Skip();
104 }
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...

References m_stateButton, m_stateMenu, and Refresh().

Referenced by SPLIT_BUTTON().

◆ OnLeftButtonDown()

void SPLIT_BUTTON::OnLeftButtonDown ( wxMouseEvent &  aEvent)
protected

Definition at line 158 of file split_button.cpp.

159 {
160  m_bLButtonDown = true;
161 
162  int x = -1;
163  int y = -1;
164  aEvent.GetPosition( &x, &y );
165 
166  if( x >= ( GetSize().GetWidth() - m_arrowButtonWidth ) )
167  {
168  m_stateButton = 0;
169  m_stateMenu = wxCONTROL_PRESSED;
170  Refresh();
171 
172  wxSize size = GetSize();
173  wxPoint position;
174  position.x = 0;
175  position.y = size.GetHeight();
176  PopupMenu( m_pMenu, position );
177 
178  m_stateMenu = 0;
179  Refresh();
180  }
181  else
182  {
183  m_stateButton = wxCONTROL_PRESSED;
184  m_stateMenu = wxCONTROL_PRESSED;
185  Refresh();
186  }
187 
188  aEvent.Skip();
189 }
bool m_bLButtonDown
Definition: split_button.h:65
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxMenu * m_pMenu
Definition: split_button.h:67
const int m_arrowButtonWidth
Definition: split_button.h:63

References m_arrowButtonWidth, m_bLButtonDown, m_pMenu, m_stateButton, m_stateMenu, and Refresh().

Referenced by SPLIT_BUTTON().

◆ OnLeftButtonUp()

void SPLIT_BUTTON::OnLeftButtonUp ( wxMouseEvent &  aEvent)
protected

Definition at line 127 of file split_button.cpp.

128 {
129  m_stateButton = 0;
130  m_stateMenu = 0;
131 
132  Refresh();
133 
134  int x = -1;
135  int y = -1;
136  aEvent.GetPosition( &x, &y );
137 
138  if( x < ( GetSize().GetWidth() - m_arrowButtonWidth ) )
139  {
140  wxEvtHandler* pEventHandler = GetEventHandler();
141  wxASSERT( pEventHandler );
142 
143  pEventHandler->CallAfter(
144  [=]()
145  {
146  wxCommandEvent evt( wxEVT_BUTTON, GetId() );
147  evt.SetEventObject( this );
148  GetEventHandler()->ProcessEvent( evt );
149  } );
150  }
151 
152  m_bLButtonDown = false;
153 
154  aEvent.Skip();
155 }
bool m_bLButtonDown
Definition: split_button.h:65
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
const int m_arrowButtonWidth
Definition: split_button.h:63

References m_arrowButtonWidth, m_bLButtonDown, m_stateButton, m_stateMenu, and Refresh().

Referenced by SPLIT_BUTTON().

◆ OnMouseEnter()

void SPLIT_BUTTON::OnMouseEnter ( wxMouseEvent &  aEvent)
protected

Definition at line 117 of file split_button.cpp.

118 {
119  m_stateButton = wxCONTROL_CURRENT;
120  m_stateMenu = wxCONTROL_CURRENT;
121  Refresh();
122 
123  aEvent.Skip();
124 }
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...

References m_stateButton, m_stateMenu, and Refresh().

Referenced by SPLIT_BUTTON().

◆ OnMouseLeave()

void SPLIT_BUTTON::OnMouseLeave ( wxMouseEvent &  aEvent)
protected

Definition at line 107 of file split_button.cpp.

108 {
109  m_stateButton = 0;
110  m_stateMenu = 0;
111  Refresh();
112 
113  aEvent.Skip();
114 }
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...

References m_stateButton, m_stateMenu, and Refresh().

Referenced by SPLIT_BUTTON().

◆ OnPaint()

void SPLIT_BUTTON::OnPaint ( wxPaintEvent &  WXUNUSEDaEvent)
protected

Definition at line 192 of file split_button.cpp.

193 {
194  wxPaintDC dc( this );
195  wxSize size = GetSize();
196  const int width = size.GetWidth() - m_arrowButtonWidth;
197 
198  // Draw first part of button
199  wxRect r1;
200  r1.x = 0;
201  r1.y = 0;
202  r1.width = width + 2;
203  r1.height = size.GetHeight();
204 
205  wxRendererNative::Get().DrawPushButton( this, dc, r1, m_stateButton );
206 
207  SetForegroundColour( m_bIsEnable ? m_colorNormal : m_colorDisabled );
208 
209  if( m_bitmap.IsOk() )
210  {
211  wxMemoryDC mdc( m_bitmap );
212 
213  r1.x = ( width - m_bitmap.GetWidth() ) / 2;
214 
215  if( r1.x < 0 )
216  r1.x = 0;
217 
218  r1.y += ( size.GetHeight() - m_bitmap.GetHeight() ) / 2;
219 
220  dc.Blit( wxPoint( r1.x, r1.y ), m_bitmap.GetSize(), &mdc, wxPoint( 0, 0 ), wxCOPY, true );
221  }
222  else
223  {
224  r1.y += ( size.GetHeight() - GetCharHeight() ) / 2;
225  dc.DrawLabel( m_label, r1, wxALIGN_CENTER_HORIZONTAL );
226  }
227 
228  // Draw second part of button
229  wxRect r2;
230  r2.x = width - 2;
231  r2.y = 0;
232  r2.width = m_arrowButtonWidth;
233  r2.height = size.GetHeight();
234 
235  wxRendererNative::Get().DrawPushButton( this, dc, r2, m_stateMenu );
236  wxRendererNative::Get().DrawDropArrow( this, dc, r2, m_stateMenu );
237 }
bool m_bIsEnable
Definition: split_button.h:60
wxBitmap m_bitmap
Definition: split_button.h:68
wxColor m_colorNormal
Definition: split_button.h:61
const int m_arrowButtonWidth
Definition: split_button.h:63
wxString m_label
Definition: split_button.h:66
wxColor m_colorDisabled
Definition: split_button.h:62

References m_arrowButtonWidth, m_bIsEnable, m_bitmap, m_colorDisabled, m_colorNormal, m_label, m_stateButton, and m_stateMenu.

Referenced by SPLIT_BUTTON().

◆ SetBitmap()

void SPLIT_BUTTON::SetBitmap ( const wxBitmap &  aBmp)

Definition at line 83 of file split_button.cpp.

84 {
85  m_bitmap = aBmp;
86 
87  SetMinSize( wxSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() ) );
88 }
wxBitmap m_bitmap
Definition: split_button.h:68
void SetMinSize(const wxSize &aSize) override

References m_bitmap, and SetMinSize().

Referenced by PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE().

◆ SetMinSize()

void SPLIT_BUTTON::SetMinSize ( const wxSize &  aSize)
override

Definition at line 68 of file split_button.cpp.

69 {
70  m_unadjustedMinSize = aSize;
71  wxPanel::SetMinSize( wxSize( aSize.GetWidth() + m_arrowButtonWidth + m_widthPadding,
72  aSize.GetHeight() ) );
73 }
int m_widthPadding
Definition: split_button.h:64
wxSize m_unadjustedMinSize
Definition: split_button.h:69
const int m_arrowButtonWidth
Definition: split_button.h:63

References m_arrowButtonWidth, m_unadjustedMinSize, and m_widthPadding.

Referenced by PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE(), SetBitmap(), SetWidthPadding(), and SPLIT_BUTTON().

◆ SetWidthPadding()

void SPLIT_BUTTON::SetWidthPadding ( int  aPadding)

Definition at line 76 of file split_button.cpp.

77 {
78  m_widthPadding = aPadding;
80 }
int m_widthPadding
Definition: split_button.h:64
wxSize m_unadjustedMinSize
Definition: split_button.h:69
void SetMinSize(const wxSize &aSize) override

References m_unadjustedMinSize, m_widthPadding, and SetMinSize().

Referenced by PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE().

Member Data Documentation

◆ m_arrowButtonWidth

const int SPLIT_BUTTON::m_arrowButtonWidth = 20
private

Definition at line 63 of file split_button.h.

Referenced by OnLeftButtonDown(), OnLeftButtonUp(), OnPaint(), and SetMinSize().

◆ m_bIsEnable

bool SPLIT_BUTTON::m_bIsEnable = true
private

Definition at line 60 of file split_button.h.

Referenced by Enable(), and OnPaint().

◆ m_bitmap

wxBitmap SPLIT_BUTTON::m_bitmap
private

Definition at line 68 of file split_button.h.

Referenced by OnPaint(), and SetBitmap().

◆ m_bLButtonDown

bool SPLIT_BUTTON::m_bLButtonDown = false
private

Definition at line 65 of file split_button.h.

Referenced by OnLeftButtonDown(), and OnLeftButtonUp().

◆ m_colorDisabled

wxColor SPLIT_BUTTON::m_colorDisabled
private

Definition at line 62 of file split_button.h.

Referenced by OnPaint(), and SPLIT_BUTTON().

◆ m_colorNormal

wxColor SPLIT_BUTTON::m_colorNormal
private

Definition at line 61 of file split_button.h.

Referenced by OnPaint(), and SPLIT_BUTTON().

◆ m_label

wxString SPLIT_BUTTON::m_label
private

Definition at line 66 of file split_button.h.

Referenced by OnPaint(), and SPLIT_BUTTON().

◆ m_pMenu

wxMenu* SPLIT_BUTTON::m_pMenu = nullptr
private

Definition at line 67 of file split_button.h.

Referenced by GetSplitButtonMenu(), OnLeftButtonDown(), SPLIT_BUTTON(), and ~SPLIT_BUTTON().

◆ m_stateButton

int SPLIT_BUTTON::m_stateButton = 0
private

◆ m_stateMenu

int SPLIT_BUTTON::m_stateMenu = 0
private

◆ m_unadjustedMinSize

wxSize SPLIT_BUTTON::m_unadjustedMinSize
private

Definition at line 69 of file split_button.h.

Referenced by SetMinSize(), and SetWidthPadding().

◆ m_widthPadding

int SPLIT_BUTTON::m_widthPadding = 20
private

Definition at line 64 of file split_button.h.

Referenced by SetMinSize(), and SetWidthPadding().


The documentation for this class was generated from the following files: