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 96 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 182 of file grid_icon_text_helpers.cpp.

183 :
184 m_icons( icons ),
185 m_names( names )
186{
187}
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 286 of file grid_icon_text_helpers.cpp.

287{
288 aGrid->GetTable()->SetValue( aRow, aCol, m_value );
289}

References m_value.

◆ BeginEdit()

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

Definition at line 241 of file grid_icon_text_helpers.cpp.

242{
243 auto evtHandler = static_cast<wxGridCellEditorEvtHandler*>( m_control->GetEventHandler() );
244
245 // Don't immediately end if we get a kill focus event within BeginEdit
246 evtHandler->SetInSetFocus( true );
247
248 m_value = aGrid->GetTable()->GetValue( aRow, aCol );
249
250 Combo()->SetSelection( Combo()->FindString( m_value ) );
251 Combo()->SetFocus();
252
253#ifdef __WXOSX_COCOA__
254 // This is a work around for the combobox being simply dismissed when a
255 // choice is made in it under OS X. The bug is almost certainly due to a
256 // problem in focus events generation logic but it's not obvious to fix and
257 // for now this at least allows one to use wxGrid.
258 Combo()->Popup();
259#endif
260
261 // When dropping down the menu, a kill focus event
262 // happens after this point, so we can't reset the flag yet.
263#if !defined(__WXGTK20__)
264 evtHandler->SetInSetFocus( false );
265#endif
266}
wxBitmapComboBox * Combo() const

References Combo(), and m_value.

◆ Clone()

wxGridCellEditor * GRID_CELL_ICON_TEXT_POPUP::Clone ( ) const
override

Definition at line 190 of file grid_icon_text_helpers.cpp.

191{
193}
GRID_CELL_ICON_TEXT_POPUP(const std::vector< BITMAPS > &icons, const wxArrayString &names)

References GRID_CELL_ICON_TEXT_POPUP(), m_icons, and m_names.

◆ Combo()

wxBitmapComboBox * GRID_CELL_ICON_TEXT_POPUP::Combo ( ) const
inlineprotected

Definition at line 114 of file grid_icon_text_helpers.h.

114{ 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 196 of file grid_icon_text_helpers.cpp.

198{
199 m_control = new wxBitmapComboBox( aParent, aId, wxEmptyString, wxDefaultPosition,
200 wxDefaultSize, 0, nullptr,
201 wxCB_READONLY | wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxBORDER_NONE );
202
203 for( unsigned i = 0; i < m_names.size(); ++i )
204 {
205 // note that the set of icons might be smaller than the set of labels if
206 // the last label is <...>.
207 if( i < m_icons.size() && m_icons[ i ] != BITMAPS::INVALID_BITMAP )
208 Combo()->Append( m_names[ i ], KiBitmap( m_icons[ i ] ) );
209 else
210 Combo()->Append( m_names[ i ] );
211 }
212
213 wxGridCellEditor::Create(aParent, aId, aEventHandler);
214}
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
@ INVALID_BITMAP

References Combo(), INVALID_BITMAP, 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 269 of file grid_icon_text_helpers.cpp.

271{
272 const wxString value = Combo()->GetValue();
273
274 if( value == m_value )
275 return false;
276
277 m_value = value;
278
279 if( aNewVal )
280 *aNewVal = value;
281
282 return true;
283}

References Combo(), and m_value.

◆ GetValue()

wxString GRID_CELL_ICON_TEXT_POPUP::GetValue ( ) const
override

Definition at line 217 of file grid_icon_text_helpers.cpp.

218{
219 return Combo()->GetValue();
220}

References Combo().

◆ Reset()

void GRID_CELL_ICON_TEXT_POPUP::Reset ( )
override

Definition at line 292 of file grid_icon_text_helpers.cpp.

293{
294 Combo()->SetSelection( Combo()->FindString( m_value ) );
295}

References Combo(), and m_value.

◆ SetSize()

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

Definition at line 223 of file grid_icon_text_helpers.cpp.

224{
225 wxRect rect( aRect );
226 rect.Inflate( -1 );
227
228#if !defined( __WXMSW__ ) && !defined( __WXGTK20__ )
229 // Only implemented in generic wxBitmapComboBox; MSW and GTK use native controls
230 Combo()->SetButtonPosition( 0, 0, wxRIGHT, 2 );
231#endif
232
233#if defined( __WXMAC__ )
234 rect.Inflate( 3 ); // no FOCUS_RING, even on Mac
235#endif
236
237 Combo()->SetSize( rect, wxSIZE_ALLOW_MINUS_ONE );
238}

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 116 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 117 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 118 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: