+
+// ----------------------------------------------------------------------------
+// wxGridCellEditor
+// ----------------------------------------------------------------------------
+
+wxGridCellEditor::wxGridCellEditor()
+{
+ m_control = NULL;
+}
+
+
+wxGridCellEditor::~wxGridCellEditor()
+{
+ Destroy();
+}
+
+
+void wxGridCellEditor::Destroy()
+{
+ if (m_control) {
+ m_control->Destroy();
+ m_control = NULL;
+ }
+}
+
+void wxGridCellEditor::Show(bool show)
+{
+ wxASSERT_MSG(m_control,
+ wxT("The wxGridCellEditor must be Created first!"));
+ m_control->Show(show);
+}
+
+void wxGridCellEditor::SetSize(const wxRect& rect)
+{
+ wxASSERT_MSG(m_control,
+ wxT("The wxGridCellEditor must be Created first!"));
+ m_control->SetSize(rect);
+}
+
+void wxGridCellEditor::HandleReturn(wxKeyEvent& event)
+{
+ event.Skip();
+}
+
+
+wxGridCellTextEditor::wxGridCellTextEditor()
+{
+}
+
+void wxGridCellTextEditor::Create(wxWindow* parent,
+ wxWindowID id,
+ const wxPoint& pos,
+ const wxSize& size,
+ wxEvtHandler* evtHandler)
+{
+ m_control = new wxTextCtrl(parent, -1, "", pos, size
+#if defined(__WXMSW__)
+ , wxTE_MULTILINE | wxTE_NO_VSCROLL
+#endif
+ );
+
+ if (evtHandler)
+ m_control->PushEventHandler(evtHandler);
+}
+
+
+void wxGridCellTextEditor::BeginEdit(int row, int col, wxGrid* grid,
+ wxGridCellAttr* attr)
+{
+ wxASSERT_MSG(m_control,
+ wxT("The wxGridCellEditor must be Created first!"));
+
+ m_startValue = grid->GetTable()->GetValue(row, col);
+ ((wxTextCtrl*)m_control)->SetValue(m_startValue);
+ ((wxTextCtrl*)m_control)->SetInsertionPointEnd();
+ ((wxTextCtrl*)m_control)->SetFocus();
+
+ // ??? Should we use attr and try to set colours and font?
+}
+
+
+
+bool wxGridCellTextEditor::EndEdit(int row, int col, bool saveValue,
+ wxGrid* grid, wxGridCellAttr* attr)
+{
+ wxASSERT_MSG(m_control,
+ wxT("The wxGridCellEditor must be Created first!"));
+
+ bool changed = FALSE;
+ wxString value = ((wxTextCtrl*)m_control)->GetValue();
+ if (value != m_startValue)
+ changed = TRUE;
+
+ if (changed)
+ grid->GetTable()->SetValue(row, col, value);
+ m_startValue = "";
+
+ return changed;
+}
+
+
+void wxGridCellTextEditor::Reset()
+{
+ wxASSERT_MSG(m_control,
+ wxT("The wxGridCellEditor must be Created first!"));
+
+ ((wxTextCtrl*)m_control)->SetValue(m_startValue);
+ ((wxTextCtrl*)m_control)->SetInsertionPointEnd();
+}
+
+void wxGridCellTextEditor::HandleReturn(wxKeyEvent& event)
+{
+#if defined(__WXMOTIF__) || defined(__WXGTK__)
+ // wxMotif needs a little extra help...
+ int pos = ((wxTextCtrl*)m_control)->GetInsertionPoint();
+ wxString s( ((wxTextCtrl*)m_control)->GetValue() );
+ s = s.Left(pos) + "\n" + s.Mid(pos);
+ ((wxTextCtrl*)m_control)->SetValue(s);
+ ((wxTextCtrl*)m_control)->SetInsertionPoint( pos );
+#else
+ // the other ports can handle a Return key press
+ //
+ event.Skip();
+#endif
+}
+
+
+void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event)
+{
+ switch ( event.KeyCode() )
+ {
+ case WXK_ESCAPE:
+ m_editor->Reset();
+ break;
+
+ case WXK_UP:
+ case WXK_DOWN:
+ case WXK_LEFT:
+ case WXK_RIGHT:
+ case WXK_PRIOR:
+ case WXK_NEXT:
+ case WXK_SPACE:
+ // send the event to the parent grid, skipping the
+ // event if nothing happens
+ //
+ event.Skip( m_grid->ProcessEvent( event ) );
+ break;
+
+ case WXK_RETURN:
+ if (!m_grid->ProcessEvent(event))
+ m_editor->HandleReturn(event);
+ break;
+
+ case WXK_HOME:
+ case WXK_END:
+ // send the event to the parent grid, skipping the
+ // event if nothing happens
+ //
+ event.Skip( m_grid->ProcessEvent( event ) );
+ break;
+
+ default:
+ event.Skip();
+ }
+}
+