wxGridCellEditor plugged in and operational for strings.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6005 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
897d36c241
commit
2c9a89e002
@ -122,8 +122,6 @@ public:
|
||||
// Creates the actual edit control
|
||||
virtual void Create(wxWindow* parent,
|
||||
wxWindowID id,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
wxEvtHandler* evtHandler) = 0;
|
||||
|
||||
// Size and position the edit control
|
||||
@ -147,6 +145,11 @@ public:
|
||||
// Reset the value in the control back to its starting value
|
||||
virtual void Reset() = 0;
|
||||
|
||||
// If the editor is enabled by pressing keys on the grid, this
|
||||
// will be called to let the editor do something about that key
|
||||
// if desired.
|
||||
virtual void StartingKey(wxKeyEvent& event);
|
||||
|
||||
// Some types of controls on some platforms may need some help
|
||||
// with the Return key.
|
||||
virtual void HandleReturn(wxKeyEvent& event);
|
||||
@ -166,8 +169,6 @@ public:
|
||||
|
||||
virtual void Create(wxWindow* parent,
|
||||
wxWindowID id,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
wxEvtHandler* evtHandler);
|
||||
|
||||
virtual void BeginEdit(int row, int col, wxGrid* grid,
|
||||
@ -177,6 +178,7 @@ public:
|
||||
wxGrid* grid, wxGridCellAttr* attr);
|
||||
|
||||
virtual void Reset();
|
||||
virtual void StartingKey(wxKeyEvent& event);
|
||||
virtual void HandleReturn(wxKeyEvent& event);
|
||||
|
||||
|
||||
@ -590,12 +592,7 @@ class WXDLLEXPORT wxGrid : public wxScrolledWindow
|
||||
public:
|
||||
wxGrid()
|
||||
{
|
||||
m_table = (wxGridTableBase *) NULL;
|
||||
m_gridWin = (wxGridWindow *) NULL;
|
||||
m_rowLabelWin = (wxGridRowLabelWindow *) NULL;
|
||||
m_colLabelWin = (wxGridColLabelWindow *) NULL;
|
||||
m_cornerLabelWin = (wxGridCornerLabelWindow *) NULL;
|
||||
m_cellEditCtrl = (wxWindow *) NULL;
|
||||
Create();
|
||||
}
|
||||
|
||||
wxGrid( wxWindow *parent,
|
||||
@ -693,7 +690,7 @@ public:
|
||||
void EnableCellEditControl( bool enable );
|
||||
|
||||
bool IsCellEditControlEnabled()
|
||||
{ return (m_cellEditCtrl && m_cellEditCtrlEnabled); }
|
||||
{ return m_cellEditCtrlEnabled; }
|
||||
|
||||
void ShowCellEditControl();
|
||||
void HideCellEditControl();
|
||||
@ -1154,6 +1151,8 @@ protected:
|
||||
// looks for the attr in cache, if not found asks the table and caches the
|
||||
// result
|
||||
wxGridCellAttr *GetCellAttr(int row, int col) const;
|
||||
wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords )
|
||||
{ return GetCellAttr( coords.GetRow(), coords.GetCol() ); }
|
||||
|
||||
// the default cell attr object for cells that don't have their own
|
||||
wxGridCellAttr* m_defaultCellAttr;
|
||||
@ -1204,8 +1203,6 @@ protected:
|
||||
wxCursor m_colResizeCursor;
|
||||
|
||||
bool m_editable; // applies to whole grid
|
||||
int m_editCtrlType; // for current cell
|
||||
wxWindow* m_cellEditCtrl;
|
||||
bool m_cellEditCtrlEnabled;
|
||||
|
||||
|
||||
|
@ -314,19 +314,24 @@ void wxGridCellEditor::HandleReturn(wxKeyEvent& event)
|
||||
}
|
||||
|
||||
|
||||
void wxGridCellEditor::StartingKey(wxKeyEvent& event)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
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
|
||||
m_control = new wxTextCtrl(parent, -1, "",
|
||||
wxDefaultPosition, wxDefaultSize
|
||||
#if defined(__WXMSW__)
|
||||
, wxTE_MULTILINE | wxTE_NO_VSCROLL
|
||||
, wxTE_MULTILINE | wxTE_NO_VSCROLL // necessary ???
|
||||
#endif
|
||||
);
|
||||
|
||||
@ -364,7 +369,9 @@ bool wxGridCellTextEditor::EndEdit(int row, int col, bool saveValue,
|
||||
|
||||
if (changed)
|
||||
grid->GetTable()->SetValue(row, col, value);
|
||||
|
||||
m_startValue = "";
|
||||
((wxTextCtrl*)m_control)->SetValue(m_startValue);
|
||||
|
||||
return changed;
|
||||
}
|
||||
@ -379,6 +386,22 @@ void wxGridCellTextEditor::Reset()
|
||||
((wxTextCtrl*)m_control)->SetInsertionPointEnd();
|
||||
}
|
||||
|
||||
|
||||
void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
|
||||
{
|
||||
wxASSERT_MSG(m_control,
|
||||
wxT("The wxGridCellEditor must be Created first!"));
|
||||
|
||||
int code = event.KeyCode();
|
||||
if (code >= 32 && code < 255) {
|
||||
wxString st((char)code);
|
||||
if (! event.ShiftDown())
|
||||
st.LowerCase();
|
||||
((wxTextCtrl*)m_control)->AppendText(st);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxGridCellTextEditor::HandleReturn(wxKeyEvent& event)
|
||||
{
|
||||
#if defined(__WXMOTIF__) || defined(__WXGTK__)
|
||||
@ -402,33 +425,30 @@ void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event)
|
||||
{
|
||||
case WXK_ESCAPE:
|
||||
m_editor->Reset();
|
||||
m_grid->EnableCellEditControl(FALSE);
|
||||
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_UP:
|
||||
// case WXK_DOWN:
|
||||
// case WXK_LEFT:
|
||||
// case WXK_RIGHT:
|
||||
// case WXK_PRIOR:
|
||||
// case WXK_NEXT:
|
||||
// case WXK_SPACE:
|
||||
// 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;
|
||||
|
||||
case WXK_TAB:
|
||||
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();
|
||||
@ -1729,7 +1749,8 @@ void wxGrid::Create()
|
||||
|
||||
m_table = (wxGridTableBase *) NULL;
|
||||
m_ownTable = FALSE;
|
||||
m_cellEditCtrl = (wxWindow *) NULL;
|
||||
|
||||
m_cellEditCtrlEnabled = FALSE;
|
||||
|
||||
m_defaultCellAttr = new wxGridCellAttr;
|
||||
m_defaultCellAttr->SetDefAttr(m_defaultCellAttr);
|
||||
@ -1921,23 +1942,6 @@ void wxGrid::Init()
|
||||
m_inOnKeyDown = FALSE;
|
||||
m_batchCount = 0;
|
||||
|
||||
// TODO: extend this to other types of controls
|
||||
//
|
||||
m_cellEditCtrl = new wxGridTextCtrl( m_gridWin,
|
||||
this,
|
||||
FALSE,
|
||||
wxGRID_CELLCTRL,
|
||||
"",
|
||||
wxPoint(1,1),
|
||||
wxSize(1,1)
|
||||
#if defined(__WXMSW__)
|
||||
, wxTE_MULTILINE | wxTE_NO_VSCROLL
|
||||
#endif
|
||||
);
|
||||
|
||||
m_cellEditCtrl->Show( FALSE );
|
||||
m_cellEditCtrlEnabled = FALSE;
|
||||
m_editCtrlType = wxGRID_TEXTCTRL;
|
||||
}
|
||||
|
||||
|
||||
@ -3582,6 +3586,13 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
|
||||
}
|
||||
break;
|
||||
|
||||
case WXK_TAB:
|
||||
if (event.ShiftDown())
|
||||
MoveCursorLeft();
|
||||
else
|
||||
MoveCursorRight();
|
||||
break;
|
||||
|
||||
case WXK_HOME:
|
||||
if ( event.ControlDown() )
|
||||
{
|
||||
@ -3618,6 +3629,7 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
|
||||
case WXK_SHIFT:
|
||||
case WXK_ALT:
|
||||
case WXK_CONTROL:
|
||||
case WXK_CAPITAL:
|
||||
event.Skip();
|
||||
break;
|
||||
|
||||
@ -3634,9 +3646,11 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
|
||||
//
|
||||
if ( !IsCellEditControlEnabled() )
|
||||
EnableCellEditControl( TRUE );
|
||||
wxKeyEvent evt(event);
|
||||
evt.SetEventObject( m_cellEditCtrl );
|
||||
m_cellEditCtrl->GetEventHandler()->ProcessEvent( evt );
|
||||
if (IsCellEditControlEnabled()) {
|
||||
wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords);
|
||||
attr->GetEditor()->StartingKey(event);
|
||||
attr->DecRef();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -3669,6 +3683,7 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords )
|
||||
{
|
||||
HideCellEditControl();
|
||||
SaveEditControlValue();
|
||||
EnableCellEditControl(FALSE);
|
||||
|
||||
// Clear the old current cell highlight
|
||||
wxRect r = BlockToDeviceRect(m_currentCellCoords, m_currentCellCoords);
|
||||
@ -4125,35 +4140,30 @@ void wxGrid::EnableEditing( bool edit )
|
||||
{
|
||||
m_editable = edit;
|
||||
|
||||
// TODO: extend this for other edit control types
|
||||
//
|
||||
if ( m_editCtrlType == wxGRID_TEXTCTRL )
|
||||
{
|
||||
((wxTextCtrl *)m_cellEditCtrl)->SetEditable( m_editable );
|
||||
}
|
||||
EnableCellEditControl(m_editable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxGrid::EnableCellEditControl( bool enable )
|
||||
{
|
||||
if (! m_editable)
|
||||
return;
|
||||
|
||||
if ( m_currentCellCoords == wxGridNoCellCoords )
|
||||
SetCurrentCell( 0, 0 );
|
||||
if ( m_cellEditCtrl &&
|
||||
enable != m_cellEditCtrlEnabled )
|
||||
{
|
||||
|
||||
if ( enable != m_cellEditCtrlEnabled )
|
||||
{
|
||||
if ( enable )
|
||||
{
|
||||
m_cellEditCtrlEnabled = enable;
|
||||
SetEditControlValue();
|
||||
// requires m_cellEditCtrlEnabled to be already true
|
||||
ShowCellEditControl();
|
||||
}
|
||||
else
|
||||
{
|
||||
HideCellEditControl();
|
||||
// requires m_cellEditCtrlEnabled to be still true
|
||||
SaveEditControlValue();
|
||||
m_cellEditCtrlEnabled = enable;
|
||||
}
|
||||
@ -4163,8 +4173,6 @@ void wxGrid::EnableCellEditControl( bool enable )
|
||||
|
||||
void wxGrid::ShowCellEditControl()
|
||||
{
|
||||
wxRect rect;
|
||||
|
||||
if ( IsCellEditControlEnabled() )
|
||||
{
|
||||
if ( !IsVisible( m_currentCellCoords ) )
|
||||
@ -4173,7 +4181,9 @@ void wxGrid::ShowCellEditControl()
|
||||
}
|
||||
else
|
||||
{
|
||||
rect = CellToRect( m_currentCellCoords );
|
||||
wxRect rect = CellToRect( m_currentCellCoords );
|
||||
int row = m_currentCellCoords.GetRow();
|
||||
int col = m_currentCellCoords.GetCol();
|
||||
|
||||
// convert to scrolled coords
|
||||
//
|
||||
@ -4189,8 +4199,7 @@ void wxGrid::ShowCellEditControl()
|
||||
//
|
||||
int extra;
|
||||
#if defined(__WXMOTIF__)
|
||||
if ( m_currentCellCoords.GetRow() == 0 ||
|
||||
m_currentCellCoords.GetCol() == 0 )
|
||||
if ( row == 0 || col == 0 )
|
||||
{
|
||||
extra = 2;
|
||||
}
|
||||
@ -4199,8 +4208,7 @@ void wxGrid::ShowCellEditControl()
|
||||
extra = 4;
|
||||
}
|
||||
#else
|
||||
if ( m_currentCellCoords.GetRow() == 0 ||
|
||||
m_currentCellCoords.GetCol() == 0 )
|
||||
if ( row == 0 || col == 0 )
|
||||
{
|
||||
extra = 1;
|
||||
}
|
||||
@ -4226,33 +4234,18 @@ void wxGrid::ShowCellEditControl()
|
||||
rect.SetBottom( rect.GetBottom() + 2*extra );
|
||||
#endif
|
||||
|
||||
m_cellEditCtrl->SetSize( rect );
|
||||
m_cellEditCtrl->Show( TRUE );
|
||||
|
||||
switch ( m_editCtrlType )
|
||||
{
|
||||
case wxGRID_TEXTCTRL:
|
||||
((wxTextCtrl *) m_cellEditCtrl)->SetInsertionPointEnd();
|
||||
break;
|
||||
|
||||
case wxGRID_CHECKBOX:
|
||||
// TODO: anything ???
|
||||
//
|
||||
break;
|
||||
|
||||
case wxGRID_CHOICE:
|
||||
// TODO: anything ???
|
||||
//
|
||||
break;
|
||||
|
||||
case wxGRID_COMBOBOX:
|
||||
// TODO: anything ???
|
||||
//
|
||||
break;
|
||||
wxGridCellAttr* attr = GetCellAttr(row, col);
|
||||
wxGridCellEditor* editor = attr->GetEditor();
|
||||
if (! editor->IsCreated()) {
|
||||
editor->Create(m_gridWin, -1,
|
||||
new wxGridCellEditorEvtHandler(this, editor));
|
||||
}
|
||||
|
||||
m_cellEditCtrl->SetFocus();
|
||||
}
|
||||
editor->SetSize( rect );
|
||||
editor->Show( TRUE );
|
||||
editor->BeginEdit(row, col, this, attr);
|
||||
attr->DecRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4261,94 +4254,34 @@ void wxGrid::HideCellEditControl()
|
||||
{
|
||||
if ( IsCellEditControlEnabled() )
|
||||
{
|
||||
m_cellEditCtrl->Show( FALSE );
|
||||
SetFocus();
|
||||
int row = m_currentCellCoords.GetRow();
|
||||
int col = m_currentCellCoords.GetCol();
|
||||
|
||||
wxGridCellAttr* attr = GetCellAttr(row, col);
|
||||
attr->GetEditor()->Show( FALSE );
|
||||
attr->DecRef();
|
||||
m_gridWin->SetFocus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxGrid::SetEditControlValue( const wxString& value )
|
||||
{
|
||||
if ( m_table )
|
||||
{
|
||||
wxString s;
|
||||
if ( !value )
|
||||
s = GetCellValue(m_currentCellCoords);
|
||||
else
|
||||
s = value;
|
||||
|
||||
if ( IsCellEditControlEnabled() )
|
||||
{
|
||||
switch ( m_editCtrlType )
|
||||
{
|
||||
case wxGRID_TEXTCTRL:
|
||||
((wxGridTextCtrl *)m_cellEditCtrl)->SetStartValue(s);
|
||||
break;
|
||||
|
||||
case wxGRID_CHECKBOX:
|
||||
// TODO: implement this
|
||||
//
|
||||
break;
|
||||
|
||||
case wxGRID_CHOICE:
|
||||
// TODO: implement this
|
||||
//
|
||||
break;
|
||||
|
||||
case wxGRID_COMBOBOX:
|
||||
// TODO: implement this
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxGrid::SaveEditControlValue()
|
||||
{
|
||||
if ( m_table )
|
||||
{
|
||||
wxWindow *ctrl = (wxWindow *)NULL;
|
||||
if (IsCellEditControlEnabled()) {
|
||||
int row = m_currentCellCoords.GetRow();
|
||||
int col = m_currentCellCoords.GetCol();
|
||||
|
||||
if ( IsCellEditControlEnabled() )
|
||||
{
|
||||
ctrl = m_cellEditCtrl;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
wxGridCellAttr* attr = GetCellAttr(row, col);
|
||||
bool changed = attr->GetEditor()->EndEdit(row, col, TRUE, this, attr);
|
||||
|
||||
bool valueChanged = FALSE;
|
||||
attr->DecRef();
|
||||
|
||||
switch ( m_editCtrlType )
|
||||
{
|
||||
case wxGRID_TEXTCTRL:
|
||||
valueChanged = (((wxGridTextCtrl *)ctrl)->GetValue() !=
|
||||
((wxGridTextCtrl *)ctrl)->GetStartValue());
|
||||
SetCellValue( m_currentCellCoords,
|
||||
((wxTextCtrl *) ctrl)->GetValue() );
|
||||
break;
|
||||
|
||||
case wxGRID_CHECKBOX:
|
||||
// TODO: implement this
|
||||
//
|
||||
break;
|
||||
|
||||
case wxGRID_CHOICE:
|
||||
// TODO: implement this
|
||||
//
|
||||
break;
|
||||
|
||||
case wxGRID_COMBOBOX:
|
||||
// TODO: implement this
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
if ( valueChanged )
|
||||
{
|
||||
if (changed) {
|
||||
SendEvent( EVT_GRID_CELL_CHANGE,
|
||||
m_currentCellCoords.GetRow(),
|
||||
m_currentCellCoords.GetCol() );
|
||||
|
Loading…
Reference in New Issue
Block a user