KiCad PCB EDA Suite
GRID_CELL_TEXT_BUTTON Class Reference

#include <grid_text_button_helpers.h>

Inheritance diagram for GRID_CELL_TEXT_BUTTON:
GRID_CELL_FOOTPRINT_ID_EDITOR GRID_CELL_PATH_EDITOR GRID_CELL_SYMBOL_ID_EDITOR GRID_CELL_SYMLIB_EDITOR GRID_CELL_URL_EDITOR

Public Member Functions

 GRID_CELL_TEXT_BUTTON ()
 
wxString GetValue () const override
 
void SetSize (const wxRect &aRect) override
 
void StartingKey (wxKeyEvent &event) override
 
void BeginEdit (int aRow, int aCol, wxGrid *aGrid) override
 
bool EndEdit (int, int, const wxGrid *, const wxString &, wxString *aNewVal) override
 
void ApplyEdit (int aRow, int aCol, wxGrid *aGrid) override
 
void Reset () override
 

Protected Member Functions

wxComboCtrl * Combo () const
 
 wxDECLARE_NO_COPY_CLASS (GRID_CELL_TEXT_BUTTON)
 

Protected Attributes

wxString m_value
 

Detailed Description

Definition at line 36 of file grid_text_button_helpers.h.

Constructor & Destructor Documentation

◆ GRID_CELL_TEXT_BUTTON()

GRID_CELL_TEXT_BUTTON::GRID_CELL_TEXT_BUTTON ( )
inline

Definition at line 39 of file grid_text_button_helpers.h.

39 {};

Member Function Documentation

◆ ApplyEdit()

void GRID_CELL_TEXT_BUTTON::ApplyEdit ( int  aRow,
int  aCol,
wxGrid *  aGrid 
)
override

Definition at line 143 of file grid_text_button_helpers.cpp.

144 {
145  aGrid->GetTable()->SetValue( aRow, aCol, m_value );
146 }

References m_value.

◆ BeginEdit()

void GRID_CELL_TEXT_BUTTON::BeginEdit ( int  aRow,
int  aCol,
wxGrid *  aGrid 
)
override

Definition at line 113 of file grid_text_button_helpers.cpp.

114 {
115  auto evtHandler = static_cast< wxGridCellEditorEvtHandler* >( m_control->GetEventHandler() );
116 
117  // Don't immediately end if we get a kill focus event within BeginEdit
118  evtHandler->SetInSetFocus( true );
119 
120  m_value = aGrid->GetTable()->GetValue( aRow, aCol );
121 
122  Combo()->SetValue( m_value );
123  Combo()->SetFocus();
124 }
wxComboCtrl * Combo() const

References Combo(), and m_value.

◆ Combo()

wxComboCtrl* GRID_CELL_TEXT_BUTTON::Combo ( ) const
inlineprotected

◆ EndEdit()

bool GRID_CELL_TEXT_BUTTON::EndEdit ( int  ,
int  ,
const wxGrid *  ,
const wxString &  ,
wxString *  aNewVal 
)
override

Definition at line 127 of file grid_text_button_helpers.cpp.

128 {
129  const wxString value = Combo()->GetValue();
130 
131  if( value == m_value )
132  return false;
133 
134  m_value = value;
135 
136  if( aNewVal )
137  *aNewVal = value;
138 
139  return true;
140 }
wxComboCtrl * Combo() const

References Combo(), and m_value.

◆ GetValue()

wxString GRID_CELL_TEXT_BUTTON::GetValue ( ) const
override

Definition at line 45 of file grid_text_button_helpers.cpp.

46 {
47  return Combo()->GetValue();
48 }
wxComboCtrl * Combo() const

References Combo().

◆ Reset()

void GRID_CELL_TEXT_BUTTON::Reset ( )
override

Definition at line 149 of file grid_text_button_helpers.cpp.

150 {
151  Combo()->SetValue( m_value );
152 }
wxComboCtrl * Combo() const

References Combo(), and m_value.

◆ SetSize()

void GRID_CELL_TEXT_BUTTON::SetSize ( const wxRect &  aRect)
override

Definition at line 51 of file grid_text_button_helpers.cpp.

52 {
53  wxRect rect( aRect );
54  rect.Inflate( -1 );
55 
56 #if defined( __WXMAC__ )
57  rect.Inflate( 3 ); // no FOCUS_RING, even on Mac
58 #endif
59 
60  Combo()->SetSize( rect, wxSIZE_ALLOW_MINUS_ONE );
61 }
wxComboCtrl * Combo() const

References Combo().

◆ StartingKey()

void GRID_CELL_TEXT_BUTTON::StartingKey ( wxKeyEvent &  event)
override

Definition at line 64 of file grid_text_button_helpers.cpp.

65 {
66  // Note: this is a copy of wxGridCellTextEditor's StartingKey()
67 
68  // Since this is now happening in the EVT_CHAR event EmulateKeyPress is no
69  // longer an appropriate way to get the character into the text control.
70  // Do it ourselves instead. We know that if we get this far that we have
71  // a valid character, so not a whole lot of testing needs to be done.
72 
73  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( Combo() );
74  int ch;
75 
76  bool isPrintable;
77 
78 #if wxUSE_UNICODE
79  ch = event.GetUnicodeKey();
80 
81  if( ch != WXK_NONE )
82  isPrintable = true;
83  else
84 #endif // wxUSE_UNICODE
85  {
86  ch = event.GetKeyCode();
87  isPrintable = ch >= WXK_SPACE && ch < WXK_START;
88  }
89 
90  switch( ch )
91  {
92  case WXK_DELETE:
93  // Delete the initial character when starting to edit with DELETE.
94  textEntry->Remove( 0, 1 );
95  break;
96 
97  case WXK_BACK:
98  // Delete the last character when starting to edit with BACKSPACE.
99  {
100  const long pos = textEntry->GetLastPosition();
101  textEntry->Remove( pos - 1, pos );
102  }
103  break;
104 
105  default:
106  if( isPrintable )
107  textEntry->WriteText( static_cast<wxChar>( ch ) );
108  break;
109  }
110 }
wxComboCtrl * Combo() const

References Combo().

◆ wxDECLARE_NO_COPY_CLASS()

GRID_CELL_TEXT_BUTTON::wxDECLARE_NO_COPY_CLASS ( GRID_CELL_TEXT_BUTTON  )
protected

Member Data Documentation

◆ m_value

wxString GRID_CELL_TEXT_BUTTON::m_value
protected

Definition at line 62 of file grid_text_button_helpers.h.

Referenced by ApplyEdit(), BeginEdit(), EndEdit(), and Reset().


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