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 aRow, int aCol, 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
 
void onComboCloseUp (wxCommandEvent &aEvent)
 
void onComboDropDown (wxCommandEvent &aEvent)
 
 wxDECLARE_NO_COPY_CLASS (GRID_CELL_COMBOBOX)
 

Protected Attributes

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::GRID_CELL_COMBOBOX ( const wxArrayString &  names)

Definition at line 37 of file grid_combobox.cpp.

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

Referenced by Clone().

Member Function Documentation

◆ ApplyEdit()

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

Definition at line 125 of file grid_combobox.cpp.

126 {
127  aGrid->GetTable()->SetValue( aRow, aCol, m_value );
128 }

References m_value.

◆ BeginEdit()

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

Definition at line 75 of file grid_combobox.cpp.

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  // These event handlers are needed to properly dismiss the editor when the popup is closed
83  m_control->Bind(wxEVT_COMBOBOX_DROPDOWN, &GRID_CELL_COMBOBOX::onComboDropDown, this);
84  m_control->Bind(wxEVT_COMBOBOX_CLOSEUP, &GRID_CELL_COMBOBOX::onComboCloseUp, this);
85 
86  m_value = aGrid->GetTable()->GetValue( aRow, aCol );
87 
88  Combo()->SetFocus();
89 
90  // Work around a wxWidgets bug where the drop-down is the wrong width on the first drop.
91  Combo()->Set( Combo()->GetStrings() );
92 
93 #ifdef __WXOSX_COCOA__
94  // This is a work around for the combobox being simply dismissed when a
95  // choice is made in it under OS X. The bug is almost certainly due to a
96  // problem in focus events generation logic but it's not obvious to fix and
97  // for now this at least allows one to use wxGrid.
98  Combo()->Popup();
99 #endif
100 
101  // When dropping down the menu, a kill focus event
102  // happens after this point, so we can't reset the flag yet.
103 #if !defined(__WXGTK20__)
104  evtHandler->SetInSetFocus( false );
105 #endif
106 }
void onComboDropDown(wxCommandEvent &aEvent)
void onComboCloseUp(wxCommandEvent &aEvent)
wxComboBox * Combo() const
Definition: grid_combobox.h:53

References Combo(), m_value, onComboCloseUp(), and onComboDropDown().

◆ Clone()

wxGridCellEditor * GRID_CELL_COMBOBOX::Clone ( ) const
override

Definition at line 43 of file grid_combobox.cpp.

44 {
45  return new GRID_CELL_COMBOBOX( m_names );
46 }
wxArrayString m_names
Definition: grid_combobox.h:58
GRID_CELL_COMBOBOX(const wxArrayString &names)

References GRID_CELL_COMBOBOX(), and m_names.

◆ Combo()

wxComboBox* GRID_CELL_COMBOBOX::Combo ( ) const
inlineprotected

Definition at line 53 of file grid_combobox.h.

53 { return static_cast<wxComboBox*>( m_control ); }

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

◆ Create()

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

Definition at line 49 of file grid_combobox.cpp.

50 {
51  m_control = new wxComboBox( aParent, wxID_ANY, wxEmptyString,
52  wxDefaultPosition, wxDefaultSize, m_names );
53 
54  wxGridCellEditor::Create(aParent, aId, aEventHandler);
55 }
wxArrayString m_names
Definition: grid_combobox.h:58

References m_names.

◆ EndEdit()

bool GRID_CELL_COMBOBOX::EndEdit ( int  aRow,
int  aCol,
const wxGrid *  ,
const wxString &  ,
wxString *  aNewVal 
)
override

Definition at line 109 of file grid_combobox.cpp.

110 {
111  const wxString value = Combo()->GetValue();
112 
113  if( value == m_value )
114  return false;
115 
116  m_value = value;
117 
118  if( aNewVal )
119  *aNewVal = value;
120 
121  return true;
122 }
wxComboBox * Combo() const
Definition: grid_combobox.h:53

References Combo(), and m_value.

◆ GetValue()

wxString GRID_CELL_COMBOBOX::GetValue ( ) const
override

Definition at line 57 of file grid_combobox.cpp.

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

References Combo().

◆ onComboCloseUp()

void GRID_CELL_COMBOBOX::onComboCloseUp ( wxCommandEvent &  aEvent)
protected

Definition at line 146 of file grid_combobox.cpp.

147 {
148  auto evtHandler = static_cast<wxGridCellEditorEvtHandler*>( m_control->GetEventHandler() );
149 
150  // Forward the combobox close up event to the cell event handler as a focus kill event
151  // so that the grid editor is dismissed when the combox closes, otherwise it leaves the
152  // dropdown arrow visible in the cell.
153  wxFocusEvent event( wxEVT_KILL_FOCUS, m_control->GetId() );
154  event.SetEventObject( m_control );
155  evtHandler->ProcessEvent( event );
156 }

Referenced by BeginEdit().

◆ onComboDropDown()

void GRID_CELL_COMBOBOX::onComboDropDown ( wxCommandEvent &  aEvent)
protected

Definition at line 136 of file grid_combobox.cpp.

137 {
138  auto evtHandler = static_cast<wxGridCellEditorEvtHandler*>( m_control->GetEventHandler() );
139 
140  // Once the combobox is dropped, reset the flag to allow the focus-loss handler
141  // to function and close the editor.
142  evtHandler->SetInSetFocus( false );
143 }

Referenced by BeginEdit().

◆ Reset()

void GRID_CELL_COMBOBOX::Reset ( )
override

Definition at line 131 of file grid_combobox.cpp.

132 {
133 }

◆ SetSize()

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

Definition at line 62 of file grid_combobox.cpp.

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

References Combo().

◆ wxDECLARE_NO_COPY_CLASS()

GRID_CELL_COMBOBOX::wxDECLARE_NO_COPY_CLASS ( GRID_CELL_COMBOBOX  )
protected

Member Data Documentation

◆ m_names

wxArrayString GRID_CELL_COMBOBOX::m_names
protected

Definition at line 58 of file grid_combobox.h.

Referenced by Clone(), and Create().

◆ m_value

wxString GRID_CELL_COMBOBOX::m_value
protected

Definition at line 59 of file grid_combobox.h.

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


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