KiCad PCB EDA Suite
GRID_CELL_ICON_TEXT_POPUP Class Reference

#include <grid_icon_text_helpers.h>

Inheritance diagram for GRID_CELL_ICON_TEXT_POPUP:

Public Member Functions

 GRID_CELL_ICON_TEXT_POPUP (const std::vector< BITMAP_DEF > &icons, const wxArrayString &names)
 
wxGridCellEditor * Clone () const override
 
void Create (wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) override
 
wxString GetValue () const override
 
void SetSize (const wxRect &aRect) 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

wxBitmapComboBox * Combo () const
 
 wxDECLARE_NO_COPY_CLASS (GRID_CELL_ICON_TEXT_POPUP)
 

Protected Attributes

const std::vector< BITMAP_DEF > & m_icons
 
const wxArrayString & m_names
 
wxString m_value
 

Detailed Description

Definition at line 74 of file grid_icon_text_helpers.h.

Constructor & Destructor Documentation

◆ GRID_CELL_ICON_TEXT_POPUP()

GRID_CELL_ICON_TEXT_POPUP::GRID_CELL_ICON_TEXT_POPUP ( const std::vector< BITMAP_DEF > &  icons,
const wxArrayString &  names 
)

Definition at line 118 of file grid_icon_text_helpers.cpp.

119  :
120  m_icons( icons ),
121  m_names( names )
122 {
123 }
const wxArrayString & m_names
const std::vector< BITMAP_DEF > & m_icons

Referenced by Clone().

Member Function Documentation

◆ ApplyEdit()

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

Definition at line 220 of file grid_icon_text_helpers.cpp.

221 {
222  aGrid->GetTable()->SetValue( aRow, aCol, m_value );
223 }

References m_value.

◆ BeginEdit()

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

Definition at line 175 of file grid_icon_text_helpers.cpp.

176 {
177  auto evtHandler = static_cast<wxGridCellEditorEvtHandler*>( m_control->GetEventHandler() );
178 
179  // Don't immediately end if we get a kill focus event within BeginEdit
180  evtHandler->SetInSetFocus( true );
181 
182  m_value = aGrid->GetTable()->GetValue( aRow, aCol );
183 
184  Combo()->SetSelection( Combo()->FindString( m_value ) );
185  Combo()->SetFocus();
186 
187 #ifdef __WXOSX_COCOA__
188  // This is a work around for the combobox being simply dismissed when a
189  // choice is made in it under OS X. The bug is almost certainly due to a
190  // problem in focus events generation logic but it's not obvious to fix and
191  // for now this at least allows to use wxGrid.
192  Combo()->Popup();
193 #endif
194 
195  // When dropping down the menu, a kill focus event
196  // happens after this point, so we can't reset the flag yet.
197 #if !defined(__WXGTK20__)
198  evtHandler->SetInSetFocus( false );
199 #endif
200 }
wxBitmapComboBox * Combo() const

References Combo(), and m_value.

◆ Clone()

wxGridCellEditor * GRID_CELL_ICON_TEXT_POPUP::Clone ( ) const
override

Definition at line 126 of file grid_icon_text_helpers.cpp.

127 {
129 }
const wxArrayString & m_names
GRID_CELL_ICON_TEXT_POPUP(const std::vector< BITMAP_DEF > &icons, const wxArrayString &names)
const std::vector< BITMAP_DEF > & m_icons

References GRID_CELL_ICON_TEXT_POPUP(), m_icons, and m_names.

◆ Combo()

wxBitmapComboBox* GRID_CELL_ICON_TEXT_POPUP::Combo ( ) const
inlineprotected

Definition at line 92 of file grid_icon_text_helpers.h.

92 { return static_cast<wxBitmapComboBox*>( m_control ); }

Referenced by BeginEdit(), Create(), EndEdit(), GetValue(), Reset(), and SetSize().

◆ Create()

void GRID_CELL_ICON_TEXT_POPUP::Create ( wxWindow *  aParent,
wxWindowID  aId,
wxEvtHandler *  aEventHandler 
)
override

Definition at line 132 of file grid_icon_text_helpers.cpp.

134 {
135  m_control = new wxBitmapComboBox(
136  aParent, aId, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL,
137  wxCB_READONLY | wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxBORDER_NONE );
138 
139  for( unsigned i = 0; i < m_names.size(); ++i )
140  {
141  // note that the set of icons might be smaller than the set of labels if
142  // the last label is <...>.
143  if( i < m_icons.size() )
144  Combo()->Append( m_names[ i ], KiBitmap( m_icons[ i ] ) );
145  else
146  Combo()->Append( m_names[ i ] );
147  }
148 
149  wxGridCellEditor::Create(aParent, aId, aEventHandler);
150 }
wxBitmapComboBox * Combo() const
const wxArrayString & m_names
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
const std::vector< BITMAP_DEF > & m_icons
size_t i
Definition: json11.cpp:597

References Combo(), i, KiBitmap(), m_icons, and m_names.

◆ EndEdit()

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

Definition at line 203 of file grid_icon_text_helpers.cpp.

205 {
206  const wxString value = Combo()->GetValue();
207 
208  if( value == m_value )
209  return false;
210 
211  m_value = value;
212 
213  if( aNewVal )
214  *aNewVal = value;
215 
216  return true;
217 }
wxBitmapComboBox * Combo() const

References Combo(), and m_value.

◆ GetValue()

wxString GRID_CELL_ICON_TEXT_POPUP::GetValue ( ) const
override

Definition at line 152 of file grid_icon_text_helpers.cpp.

153 {
154  return Combo()->GetValue();
155 }
wxBitmapComboBox * Combo() const

References Combo().

◆ Reset()

void GRID_CELL_ICON_TEXT_POPUP::Reset ( )
override

Definition at line 226 of file grid_icon_text_helpers.cpp.

227 {
228  Combo()->SetSelection( Combo()->FindString( m_value ) );
229 }
wxBitmapComboBox * Combo() const

References Combo(), and m_value.

◆ SetSize()

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

Definition at line 157 of file grid_icon_text_helpers.cpp.

158 {
159  wxRect rect( aRect );
160  rect.Inflate( -1 );
161 
162 #if !defined( __WXMSW__ ) && !defined( __WXGTK20__ )
163  // Only implemented in generic wxBitmapComboBox; MSW and GTK use native controls
164  Combo()->SetButtonPosition( 0, 0, wxRIGHT, 2 );
165 #endif
166 
167 #if defined( __WXMAC__ )
168  rect.Inflate( 3 ); // no FOCUS_RING, even on Mac
169 #endif
170 
171  Combo()->SetSize( rect, wxSIZE_ALLOW_MINUS_ONE );
172 }
wxBitmapComboBox * Combo() const

References Combo().

◆ wxDECLARE_NO_COPY_CLASS()

GRID_CELL_ICON_TEXT_POPUP::wxDECLARE_NO_COPY_CLASS ( GRID_CELL_ICON_TEXT_POPUP  )
protected

Member Data Documentation

◆ m_icons

const std::vector<BITMAP_DEF>& GRID_CELL_ICON_TEXT_POPUP::m_icons
protected

Definition at line 94 of file grid_icon_text_helpers.h.

Referenced by Clone(), and Create().

◆ m_names

const wxArrayString& GRID_CELL_ICON_TEXT_POPUP::m_names
protected

Definition at line 95 of file grid_icon_text_helpers.h.

Referenced by Clone(), and Create().

◆ m_value

wxString GRID_CELL_ICON_TEXT_POPUP::m_value
protected

Definition at line 96 of file grid_icon_text_helpers.h.

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


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