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< BITMAPS > &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

std::vector< BITMAPSm_icons
 
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< BITMAPS > &  icons,
const wxArrayString &  names 
)

Definition at line 132 of file grid_icon_text_helpers.cpp.

133  :
134  m_icons( icons ),
135  m_names( names )
136 {
137 }
std::vector< BITMAPS > 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 234 of file grid_icon_text_helpers.cpp.

235 {
236  aGrid->GetTable()->SetValue( aRow, aCol, m_value );
237 }

References m_value.

◆ BeginEdit()

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

Definition at line 189 of file grid_icon_text_helpers.cpp.

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

References Combo(), and m_value.

◆ Clone()

wxGridCellEditor * GRID_CELL_ICON_TEXT_POPUP::Clone ( ) const
override

Definition at line 140 of file grid_icon_text_helpers.cpp.

141 {
143 }
GRID_CELL_ICON_TEXT_POPUP(const std::vector< BITMAPS > &icons, const wxArrayString &names)
std::vector< BITMAPS > 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 146 of file grid_icon_text_helpers.cpp.

148 {
149  m_control = new wxBitmapComboBox(
150  aParent, aId, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL,
151  wxCB_READONLY | wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxBORDER_NONE );
152 
153  for( unsigned i = 0; i < m_names.size(); ++i )
154  {
155  // note that the set of icons might be smaller than the set of labels if
156  // the last label is <...>.
157  if( i < m_icons.size() )
158  Combo()->Append( m_names[ i ], KiBitmap( m_icons[ i ] ) );
159  else
160  Combo()->Append( m_names[ i ] );
161  }
162 
163  wxGridCellEditor::Create(aParent, aId, aEventHandler);
164 }
wxBitmapComboBox * Combo() const
std::vector< BITMAPS > m_icons
#define NULL
wxBitmap KiBitmap(BITMAPS aBitmap)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104

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

◆ EndEdit()

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

Definition at line 217 of file grid_icon_text_helpers.cpp.

219 {
220  const wxString value = Combo()->GetValue();
221 
222  if( value == m_value )
223  return false;
224 
225  m_value = value;
226 
227  if( aNewVal )
228  *aNewVal = value;
229 
230  return true;
231 }
wxBitmapComboBox * Combo() const

References Combo(), and m_value.

◆ GetValue()

wxString GRID_CELL_ICON_TEXT_POPUP::GetValue ( ) const
override

Definition at line 166 of file grid_icon_text_helpers.cpp.

167 {
168  return Combo()->GetValue();
169 }
wxBitmapComboBox * Combo() const

References Combo().

◆ Reset()

void GRID_CELL_ICON_TEXT_POPUP::Reset ( )
override

Definition at line 240 of file grid_icon_text_helpers.cpp.

241 {
242  Combo()->SetSelection( Combo()->FindString( m_value ) );
243 }
wxBitmapComboBox * Combo() const

References Combo(), and m_value.

◆ SetSize()

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

Definition at line 171 of file grid_icon_text_helpers.cpp.

172 {
173  wxRect rect( aRect );
174  rect.Inflate( -1 );
175 
176 #if !defined( __WXMSW__ ) && !defined( __WXGTK20__ )
177  // Only implemented in generic wxBitmapComboBox; MSW and GTK use native controls
178  Combo()->SetButtonPosition( 0, 0, wxRIGHT, 2 );
179 #endif
180 
181 #if defined( __WXMAC__ )
182  rect.Inflate( 3 ); // no FOCUS_RING, even on Mac
183 #endif
184 
185  Combo()->SetSize( rect, wxSIZE_ALLOW_MINUS_ONE );
186 }
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

std::vector<BITMAPS> 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

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: