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)
 
void SetLabel (const wxString &aLabel) override
 

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}
wxColor m_colorNormal
Definition: split_button.h:62
wxString m_label
Definition: split_button.h:67
void OnLeftButtonUp(wxMouseEvent &aEvent)
void OnKillFocus(wxFocusEvent &aEvent)
void OnMouseLeave(wxMouseEvent &aEvent)
wxColor m_colorDisabled
Definition: split_button.h:63
wxMenu * m_pMenu
Definition: split_button.h:68
void OnLeftButtonDown(wxMouseEvent &aEvent)
void SetMinSize(const wxSize &aSize) override
void OnMouseEnter(wxMouseEvent &aEvent)
void OnPaint(wxPaintEvent &WXUNUSED(aEvent))
static const wxSize defaultSize(FRAME_T aFrameType)

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}

References m_pMenu.

Member Function Documentation

◆ Enable()

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

Definition at line 247 of file split_button.cpp.

248{
249 m_bIsEnable = aEnable;
250 wxPanel::Enable( m_bIsEnable );
251
252 if( m_bIsEnable )
253 {
254 m_stateButton = 0;
255 m_stateMenu = 0;
256 }
257 else
258 {
259 m_stateButton = wxCONTROL_DISABLED;
260 m_stateMenu = wxCONTROL_DISABLED;
261 }
262
263 Refresh();
264
265 return aEnable;
266}
bool m_bIsEnable
Definition: split_button.h:61
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 ( )

◆ OnKillFocus()

void SPLIT_BUTTON::OnKillFocus ( wxFocusEvent &  aEvent)
protected

Definition at line 104 of file split_button.cpp.

105{
106 m_stateButton = wxCONTROL_CURRENT;
107 m_stateMenu = wxCONTROL_CURRENT;
108 Refresh();
109
110 aEvent.Skip();
111}

References m_stateButton, m_stateMenu, and Refresh().

Referenced by SPLIT_BUTTON().

◆ OnLeftButtonDown()

void SPLIT_BUTTON::OnLeftButtonDown ( wxMouseEvent &  aEvent)
protected

Definition at line 165 of file split_button.cpp.

166{
167 m_bLButtonDown = true;
168
169 int x = -1;
170 int y = -1;
171 aEvent.GetPosition( &x, &y );
172
173 if( x >= ( GetSize().GetWidth() - m_arrowButtonWidth ) )
174 {
175 m_stateButton = 0;
176 m_stateMenu = wxCONTROL_PRESSED;
177 Refresh();
178
179 wxSize size = GetSize();
180 wxPoint position;
181 position.x = 0;
182 position.y = size.GetHeight();
183 PopupMenu( m_pMenu, position );
184
185 m_stateMenu = 0;
186 Refresh();
187 }
188 else
189 {
190 m_stateButton = wxCONTROL_PRESSED;
191 m_stateMenu = wxCONTROL_PRESSED;
192 Refresh();
193 }
194
195 aEvent.Skip();
196}
const int m_arrowButtonWidth
Definition: split_button.h:64
bool m_bLButtonDown
Definition: split_button.h:66

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 134 of file split_button.cpp.

135{
136 m_stateButton = 0;
137 m_stateMenu = 0;
138
139 Refresh();
140
141 int x = -1;
142 int y = -1;
143 aEvent.GetPosition( &x, &y );
144
145 if( x < ( GetSize().GetWidth() - m_arrowButtonWidth ) )
146 {
147 wxEvtHandler* pEventHandler = GetEventHandler();
148 wxASSERT( pEventHandler );
149
150 pEventHandler->CallAfter(
151 [=]()
152 {
153 wxCommandEvent evt( wxEVT_BUTTON, GetId() );
154 evt.SetEventObject( this );
155 GetEventHandler()->ProcessEvent( evt );
156 } );
157 }
158
159 m_bLButtonDown = false;
160
161 aEvent.Skip();
162}

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 124 of file split_button.cpp.

125{
126 m_stateButton = wxCONTROL_CURRENT;
127 m_stateMenu = wxCONTROL_CURRENT;
128 Refresh();
129
130 aEvent.Skip();
131}

References m_stateButton, m_stateMenu, and Refresh().

Referenced by SPLIT_BUTTON().

◆ OnMouseLeave()

void SPLIT_BUTTON::OnMouseLeave ( wxMouseEvent &  aEvent)
protected

Definition at line 114 of file split_button.cpp.

115{
116 m_stateButton = 0;
117 m_stateMenu = 0;
118 Refresh();
119
120 aEvent.Skip();
121}

References m_stateButton, m_stateMenu, and Refresh().

Referenced by SPLIT_BUTTON().

◆ OnPaint()

void SPLIT_BUTTON::OnPaint ( wxPaintEvent &  WXUNUSEDaEvent)
protected

Definition at line 199 of file split_button.cpp.

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

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}

References m_bitmap, and SetMinSize().

Referenced by DIALOG_MANAGE_REPOSITORIES::DIALOG_MANAGE_REPOSITORIES(), and PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE().

◆ SetLabel()

void SPLIT_BUTTON::SetLabel ( const wxString &  aLabel)
override

Definition at line 91 of file split_button.cpp.

92{
93 m_label = aLabel;
94 Refresh();
95}

References m_label, and Refresh().

Referenced by PANEL_PACKAGE::PANEL_PACKAGE(), and PANEL_PACKAGE::SetState().

◆ 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}
wxSize m_unadjustedMinSize
Definition: split_button.h:70
int m_widthPadding
Definition: split_button.h:65

References m_arrowButtonWidth, m_unadjustedMinSize, and m_widthPadding.

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

◆ SetWidthPadding()

void SPLIT_BUTTON::SetWidthPadding ( int  aPadding)

Member Data Documentation

◆ m_arrowButtonWidth

const int SPLIT_BUTTON::m_arrowButtonWidth = 20
private

Definition at line 64 of file split_button.h.

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

◆ m_bIsEnable

bool SPLIT_BUTTON::m_bIsEnable = true
private

Definition at line 61 of file split_button.h.

Referenced by Enable(), and OnPaint().

◆ m_bitmap

wxBitmap SPLIT_BUTTON::m_bitmap
private

Definition at line 69 of file split_button.h.

Referenced by OnPaint(), and SetBitmap().

◆ m_bLButtonDown

bool SPLIT_BUTTON::m_bLButtonDown = false
private

Definition at line 66 of file split_button.h.

Referenced by OnLeftButtonDown(), and OnLeftButtonUp().

◆ m_colorDisabled

wxColor SPLIT_BUTTON::m_colorDisabled
private

Definition at line 63 of file split_button.h.

Referenced by OnPaint(), and SPLIT_BUTTON().

◆ m_colorNormal

wxColor SPLIT_BUTTON::m_colorNormal
private

Definition at line 62 of file split_button.h.

Referenced by OnPaint(), and SPLIT_BUTTON().

◆ m_label

wxString SPLIT_BUTTON::m_label
private

Definition at line 67 of file split_button.h.

Referenced by OnPaint(), SetLabel(), and SPLIT_BUTTON().

◆ m_pMenu

wxMenu* SPLIT_BUTTON::m_pMenu = nullptr
private

Definition at line 68 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 70 of file split_button.h.

Referenced by SetMinSize(), and SetWidthPadding().

◆ m_widthPadding

int SPLIT_BUTTON::m_widthPadding = 20
private

Definition at line 65 of file split_button.h.

Referenced by SetMinSize(), and SetWidthPadding().


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