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

Definition at line 117 of file grid_icon_text_helpers.cpp.

Referenced by Clone().

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

Member Function Documentation

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

Definition at line 219 of file grid_icon_text_helpers.cpp.

References m_value.

220 {
221  aGrid->GetTable()->SetValue( aRow, aCol, m_value );
222 }
void GRID_CELL_ICON_TEXT_POPUP::BeginEdit ( int  aRow,
int  aCol,
wxGrid *  aGrid 
)
override

Definition at line 174 of file grid_icon_text_helpers.cpp.

References Combo(), and m_value.

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

Definition at line 125 of file grid_icon_text_helpers.cpp.

References GRID_CELL_ICON_TEXT_POPUP(), m_icons, and m_names.

126 {
128 }
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
wxBitmapComboBox* GRID_CELL_ICON_TEXT_POPUP::Combo ( ) const
inlineprotected

Definition at line 92 of file grid_icon_text_helpers.h.

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

92 { return static_cast<wxBitmapComboBox*>( m_control ); }
void GRID_CELL_ICON_TEXT_POPUP::Create ( wxWindow *  aParent,
wxWindowID  aId,
wxEvtHandler *  aEventHandler 
)
override

Definition at line 131 of file grid_icon_text_helpers.cpp.

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

133 {
134  m_control = new wxBitmapComboBox(
135  aParent, aId, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL,
136  wxCB_READONLY | wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxBORDER_NONE );
137 
138  for( unsigned i = 0; i < m_names.size(); ++i )
139  {
140  // note that the set of icons might be smaller than the set of labels if
141  // the last label is <...>.
142  if( i < m_icons.size() )
143  Combo()->Append( m_names[ i ], KiBitmap( m_icons[ i ] ) );
144  else
145  Combo()->Append( m_names[ i ] );
146  }
147 
148  wxGridCellEditor::Create(aParent, aId, aEventHandler);
149 }
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
bool GRID_CELL_ICON_TEXT_POPUP::EndEdit ( int  ,
int  ,
const wxGrid *  ,
const wxString &  ,
wxString *  aNewVal 
)
override

Definition at line 202 of file grid_icon_text_helpers.cpp.

References Combo(), and m_value.

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

Definition at line 151 of file grid_icon_text_helpers.cpp.

References Combo().

152 {
153  return Combo()->GetValue();
154 }
wxBitmapComboBox * Combo() const
void GRID_CELL_ICON_TEXT_POPUP::Reset ( )
override

Definition at line 225 of file grid_icon_text_helpers.cpp.

References Combo(), and m_value.

226 {
227  Combo()->SetSelection( Combo()->FindString( m_value ) );
228 }
wxBitmapComboBox * Combo() const
void GRID_CELL_ICON_TEXT_POPUP::SetSize ( const wxRect &  aRect)
override

Definition at line 156 of file grid_icon_text_helpers.cpp.

References Combo().

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

Member Data Documentation

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().

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().

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: