KiCad PCB EDA Suite
GRID_CELL_COMBOBOX Class Reference

#include <grid_combobox.h>

Inheritance diagram for GRID_CELL_COMBOBOX:

Public Member Functions

 GRID_CELL_COMBOBOX (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

wxComboBox * Combo () const
 
 wxDECLARE_NO_COPY_CLASS (GRID_CELL_COMBOBOX)
 

Protected Attributes

const wxArrayString & m_names
 
wxString m_value
 

Detailed Description

Definition at line 35 of file grid_combobox.h.

Constructor & Destructor Documentation

GRID_CELL_COMBOBOX::GRID_CELL_COMBOBOX ( const wxArrayString &  names)

Definition at line 37 of file grid_combobox.cpp.

Referenced by Clone().

37  :
38  m_names( names )
39 {
40 }
const wxArrayString & m_names
Definition: grid_combobox.h:55

Member Function Documentation

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

Definition at line 118 of file grid_combobox.cpp.

References m_value.

119 {
120  aGrid->GetTable()->SetValue( aRow, aCol, m_value );
121 }
void GRID_CELL_COMBOBOX::BeginEdit ( int  aRow,
int  aCol,
wxGrid *  aGrid 
)
override

Definition at line 75 of file grid_combobox.cpp.

References Combo(), and m_value.

76 {
77  auto evtHandler = static_cast<wxGridCellEditorEvtHandler*>( m_control->GetEventHandler() );
78 
79  // Don't immediately end if we get a kill focus event within BeginEdit
80  evtHandler->SetInSetFocus( true );
81 
82  m_value = aGrid->GetTable()->GetValue( aRow, aCol );
83 
84  Combo()->SetFocus();
85 
86 #ifdef __WXOSX_COCOA__
87  // This is a work around for the combobox being simply dismissed when a
88  // choice is made in it under OS X. The bug is almost certainly due to a
89  // problem in focus events generation logic but it's not obvious to fix and
90  // for now this at least allows to use wxGrid.
91  Combo()->Popup();
92 #endif
93 
94  // When dropping down the menu, a kill focus event
95  // happens after this point, so we can't reset the flag yet.
96 #if !defined(__WXGTK20__)
97  evtHandler->SetInSetFocus( false );
98 #endif
99 }
wxComboBox * Combo() const
Definition: grid_combobox.h:53
wxGridCellEditor * GRID_CELL_COMBOBOX::Clone ( ) const
override

Definition at line 43 of file grid_combobox.cpp.

References GRID_CELL_COMBOBOX(), and m_names.

44 {
45  return new GRID_CELL_COMBOBOX( m_names );
46 }
GRID_CELL_COMBOBOX(const wxArrayString &names)
const wxArrayString & m_names
Definition: grid_combobox.h:55
wxComboBox* GRID_CELL_COMBOBOX::Combo ( ) const
inlineprotected

Definition at line 53 of file grid_combobox.h.

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

53 { return static_cast<wxComboBox*>( m_control ); }
void GRID_CELL_COMBOBOX::Create ( wxWindow *  aParent,
wxWindowID  aId,
wxEvtHandler *  aEventHandler 
)
override

Definition at line 49 of file grid_combobox.cpp.

References m_names.

50 {
51  m_control = new wxComboBox( aParent, wxID_ANY, wxEmptyString,
52  wxDefaultPosition, wxDefaultSize, m_names );
53 
54  wxGridCellEditor::Create(aParent, aId, aEventHandler);
55 }
const wxArrayString & m_names
Definition: grid_combobox.h:55
bool GRID_CELL_COMBOBOX::EndEdit ( int  ,
int  ,
const wxGrid *  ,
const wxString &  ,
wxString *  aNewVal 
)
override

Definition at line 102 of file grid_combobox.cpp.

References Combo(), and m_value.

103 {
104  const wxString value = Combo()->GetValue();
105 
106  if( value == m_value )
107  return false;
108 
109  m_value = value;
110 
111  if( aNewVal )
112  *aNewVal = value;
113 
114  return true;
115 }
wxComboBox * Combo() const
Definition: grid_combobox.h:53
wxString GRID_CELL_COMBOBOX::GetValue ( ) const
override

Definition at line 57 of file grid_combobox.cpp.

References Combo().

58 {
59  return Combo()->GetValue();
60 }
wxComboBox * Combo() const
Definition: grid_combobox.h:53
void GRID_CELL_COMBOBOX::Reset ( )
override

Definition at line 124 of file grid_combobox.cpp.

125 {
126 }
void GRID_CELL_COMBOBOX::SetSize ( const wxRect &  aRect)
override

Definition at line 62 of file grid_combobox.cpp.

References Combo().

63 {
64  wxRect rect( aRect );
65  rect.Inflate( -1 );
66 
67 #if defined( __WXMAC__ )
68  rect.Inflate( 3 ); // no FOCUS_RING, even on Mac
69 #endif
70 
71  Combo()->SetSize( rect, wxSIZE_ALLOW_MINUS_ONE );
72 }
wxComboBox * Combo() const
Definition: grid_combobox.h:53
GRID_CELL_COMBOBOX::wxDECLARE_NO_COPY_CLASS ( GRID_CELL_COMBOBOX  )
protected

Member Data Documentation

const wxArrayString& GRID_CELL_COMBOBOX::m_names
protected

Definition at line 55 of file grid_combobox.h.

Referenced by Clone(), and Create().

wxString GRID_CELL_COMBOBOX::m_value
protected

Definition at line 56 of file grid_combobox.h.

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


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