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_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 ( )
inline

Definition at line 39 of file grid_text_button_helpers.h.

References ApplyEdit(), BeginEdit(), EndEdit(), GetValue(), Reset(), SetSize(), and StartingKey().

39 {};

Member Function Documentation

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

Definition at line 141 of file grid_text_button_helpers.cpp.

References m_value.

Referenced by GRID_CELL_TEXT_BUTTON().

142 {
143  aGrid->GetTable()->SetValue( aRow, aCol, m_value );
144 }
void GRID_CELL_TEXT_BUTTON::BeginEdit ( int  aRow,
int  aCol,
wxGrid *  aGrid 
)
override

Definition at line 111 of file grid_text_button_helpers.cpp.

References Combo(), and m_value.

Referenced by GRID_CELL_TEXT_BUTTON().

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

Definition at line 52 of file grid_text_button_helpers.h.

Referenced by BeginEdit(), EndEdit(), GetValue(), SetSize(), and StartingKey().

52 { return static_cast<wxComboCtrl*>( m_control ); }
bool GRID_CELL_TEXT_BUTTON::EndEdit ( int  ,
int  ,
const wxGrid *  ,
const wxString &  ,
wxString *  aNewVal 
)
override

Definition at line 125 of file grid_text_button_helpers.cpp.

References Combo(), and m_value.

Referenced by GRID_CELL_TEXT_BUTTON().

126 {
127  const wxString value = Combo()->GetValue();
128 
129  if( value == m_value )
130  return false;
131 
132  m_value = value;
133 
134  if( aNewVal )
135  *aNewVal = value;
136 
137  return true;
138 }
wxComboCtrl * Combo() const
wxString GRID_CELL_TEXT_BUTTON::GetValue ( ) const
override
void GRID_CELL_TEXT_BUTTON::Reset ( )
override

Definition at line 147 of file grid_text_button_helpers.cpp.

Referenced by GRID_CELL_TEXT_BUTTON().

148 {
149 }
void GRID_CELL_TEXT_BUTTON::SetSize ( const wxRect &  aRect)
override

Definition at line 50 of file grid_text_button_helpers.cpp.

References Combo().

Referenced by GRID_CELL_TEXT_BUTTON().

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

Definition at line 63 of file grid_text_button_helpers.cpp.

References Combo().

Referenced by GRID_CELL_TEXT_BUTTON().

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

Member Data Documentation

wxString GRID_CELL_TEXT_BUTTON::m_value
protected

Definition at line 54 of file grid_text_button_helpers.h.

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


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