delay getting the default editor and renderer (by data type) until

actually needed


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6228 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2000-02-23 04:45:24 +00:00
parent 7cc8c9884d
commit 28a77bc43b
2 changed files with 66 additions and 48 deletions

View File

@@ -505,8 +505,8 @@ public:
const wxColour& GetBackgroundColour() const; const wxColour& GetBackgroundColour() const;
const wxFont& GetFont() const; const wxFont& GetFont() const;
void GetAlignment(int *hAlign, int *vAlign) const; void GetAlignment(int *hAlign, int *vAlign) const;
wxGridCellRenderer *GetRenderer(wxGridCellRenderer* def) const; wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
wxGridCellEditor *GetEditor(wxGridCellEditor* def) const; wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
bool IsReadOnly() const { return m_isReadOnly; } bool IsReadOnly() const { return m_isReadOnly; }
@@ -1034,7 +1034,7 @@ public:
void SetRowLabelValue( int row, const wxString& ); void SetRowLabelValue( int row, const wxString& );
void SetColLabelValue( int col, const wxString& ); void SetColLabelValue( int col, const wxString& );
void SetGridLineColour( const wxColour& ); void SetGridLineColour( const wxColour& );
void EnableDragRowSize( bool enable = TRUE ); void EnableDragRowSize( bool enable = TRUE );
void DisableDragRowSize() { EnableDragRowSize( FALSE ); } void DisableDragRowSize() { EnableDragRowSize( FALSE ); }
bool CanDragRowSize() { return m_canDragRowSize; } bool CanDragRowSize() { return m_canDragRowSize; }

View File

@@ -423,7 +423,7 @@ void wxGridCellEditor::SetSize(const wxRect& rect)
{ {
wxASSERT_MSG(m_control, wxASSERT_MSG(m_control,
wxT("The wxGridCellEditor must be Created first!")); wxT("The wxGridCellEditor must be Created first!"));
m_control->SetSize(rect); m_control->SetSize(rect, wxSIZE_ALLOW_MINUS_ONE);
} }
void wxGridCellEditor::HandleReturn(wxKeyEvent& event) void wxGridCellEditor::HandleReturn(wxKeyEvent& event)
@@ -815,7 +815,7 @@ void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid)
wxASSERT_MSG(m_control, wxASSERT_MSG(m_control,
wxT("The wxGridCellEditor must be Created first!")); wxT("The wxGridCellEditor must be Created first!"));
if (grid->GetTable()->CanGetValueAs(row, col, wxT("bool"))) if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL))
m_startValue = grid->GetTable()->GetValueAsBool(row, col); m_startValue = grid->GetTable()->GetValueAsBool(row, col);
else else
m_startValue = !!grid->GetTable()->GetValue(row, col); m_startValue = !!grid->GetTable()->GetValue(row, col);
@@ -837,7 +837,7 @@ bool wxGridCellBoolEditor::EndEdit(int row, int col,
if ( changed ) if ( changed )
{ {
if (grid->GetTable()->CanGetValueAs(row, col, wxT("bool"))) if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL))
grid->GetTable()->SetValueAsBool(row, col, value); grid->GetTable()->SetValueAsBool(row, col, value);
else else
grid->GetTable()->SetValue(row, col, value ? _T("1") : wxEmptyString); grid->GetTable()->SetValue(row, col, value ? _T("1") : wxEmptyString);
@@ -911,11 +911,20 @@ void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
m_startValue = grid->GetTable()->GetValue(row, col); m_startValue = grid->GetTable()->GetValue(row, col);
Combo()->SetValue(m_startValue); Combo()->SetValue(m_startValue);
size_t count = m_choices.GetCount();
for (size_t i=0; i<count; i++)
{
if (m_startValue == m_choices[i])
{
Combo()->SetSelection(i);
break;
}
}
Combo()->SetInsertionPointEnd(); Combo()->SetInsertionPointEnd();
Combo()->SetFocus(); Combo()->SetFocus();
} }
bool wxGridCellChoiceEditor::EndEdit(int row, int col, bool wxGridCellChoiceEditor::EndEdit(int row, int col,
bool saveValue, bool saveValue,
wxGrid* grid) wxGrid* grid)
{ {
@@ -1326,40 +1335,48 @@ void wxGridCellAttr::GetAlignment(int *hAlign, int *vAlign) const
// GetRenderer and GetEditor use a slightly different decision path about // GetRenderer and GetEditor use a slightly different decision path about
// which to use. If a non-default attr object has one then it is used, // which attribute to use. If a non-default attr object has one then it is
// otherwise the default editor or renderer passed in is used. It should be // used, otherwise the default editor or renderer is fetched from the grid and
// the default for the data type of the cell. If it is NULL (because the // used. It should be the default for the data type of the cell. If it is
// table has a type that the grid does not have in its registry,) then the // NULL (because the table has a type that the grid does not have in its
// grid's default editor or renderer is used. // registry,) then the grid's default editor or renderer is used.
wxGridCellRenderer* wxGridCellAttr::GetRenderer(wxGridCellRenderer* def) const wxGridCellRenderer* wxGridCellAttr::GetRenderer(wxGrid* grid, int row, int col) const
{ {
if ((m_defGridAttr != this || def == NULL) && HasRenderer()) if ((m_defGridAttr != this || grid == NULL) && HasRenderer())
return m_renderer; return m_renderer; // use local attribute
else if (def)
return def; wxGridCellRenderer* renderer = NULL;
else if (m_defGridAttr != this) if (grid) // get renderer for the data type
return m_defGridAttr->GetRenderer(NULL); renderer = grid->GetDefaultRendererForCell(row, col);
else
{ if (! renderer)
// if we still don't have one then use the grid default
renderer = m_defGridAttr->GetRenderer(NULL,0,0);
if (! renderer)
wxFAIL_MSG(wxT("Missing default cell attribute")); wxFAIL_MSG(wxT("Missing default cell attribute"));
return NULL;
} return renderer;
} }
wxGridCellEditor* wxGridCellAttr::GetEditor(wxGridCellEditor* def) const wxGridCellEditor* wxGridCellAttr::GetEditor(wxGrid* grid, int row, int col) const
{ {
if ((m_defGridAttr != this || def == NULL) && HasEditor()) if ((m_defGridAttr != this || grid == NULL) && HasEditor())
return m_editor; return m_editor; // use local attribute
else if (def)
return def; wxGridCellEditor* editor = NULL;
else if (m_defGridAttr != this) if (grid) // get renderer for the data type
return m_defGridAttr->GetEditor(NULL); editor = grid->GetDefaultEditorForCell(row, col);
else
{ if (! editor)
// if we still don't have one then use the grid default
editor = m_defGridAttr->GetEditor(NULL,0,0);
if (! editor)
wxFAIL_MSG(wxT("Missing default cell attribute")); wxFAIL_MSG(wxT("Missing default cell attribute"));
return NULL;
} return editor;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -3921,7 +3938,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
EnableCellEditControl(); EnableCellEditControl();
wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords); wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords);
attr->GetEditor(GetDefaultEditorForCell(coords.GetRow(), coords.GetCol()))->StartingClick(); attr->GetEditor(this, coords.GetRow(), coords.GetCol())->StartingClick();
attr->DecRef(); attr->DecRef();
m_waitForSlowClick = FALSE; m_waitForSlowClick = FALSE;
@@ -4687,7 +4704,7 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
int row = m_currentCellCoords.GetRow(); int row = m_currentCellCoords.GetRow();
int col = m_currentCellCoords.GetCol(); int col = m_currentCellCoords.GetCol();
wxGridCellAttr* attr = GetCellAttr(row, col); wxGridCellAttr* attr = GetCellAttr(row, col);
attr->GetEditor(GetDefaultEditorForCell(row, col))->StartingKey(event); attr->GetEditor(this, row, col)->StartingKey(event);
attr->DecRef(); attr->DecRef();
} }
else else
@@ -4719,7 +4736,9 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords )
m_currentCellCoords != wxGridNoCellCoords ) m_currentCellCoords != wxGridNoCellCoords )
{ {
HideCellEditControl(); HideCellEditControl();
SaveEditControlValue(); // RD: Does disabling this cause any problems? It's called again
// in DisableCellEditControl...
// SaveEditControlValue();
DisableCellEditControl(); DisableCellEditControl();
// Clear the old current cell highlight // Clear the old current cell highlight
@@ -4839,14 +4858,13 @@ void wxGrid::DrawCell( wxDC& dc, const wxGridCellCoords& coords )
// if the editor is shown, we should use it and not the renderer // if the editor is shown, we should use it and not the renderer
if ( isCurrent && IsCellEditControlEnabled() ) if ( isCurrent && IsCellEditControlEnabled() )
{ {
attr->GetEditor(GetDefaultEditorForCell(row, col))-> attr->GetEditor(this, row, col)->PaintBackground(rect, attr);
PaintBackground(rect, attr);
} }
else else
{ {
// but all the rest is drawn by the cell renderer and hence may be // but all the rest is drawn by the cell renderer and hence may be
// customized // customized
attr->GetRenderer(GetDefaultRendererForCell(row,col))-> attr->GetRenderer(this, row, col)->
Draw(*this, *attr, dc, rect, row, col, IsInSelection(coords)); Draw(*this, *attr, dc, rect, row, col, IsInSelection(coords));
} }
@@ -5354,7 +5372,7 @@ void wxGrid::ShowCellEditControl()
rect.y--; rect.y--;
wxGridCellAttr* attr = GetCellAttr(row, col); wxGridCellAttr* attr = GetCellAttr(row, col);
wxGridCellEditor* editor = attr->GetEditor(GetDefaultEditorForCell(row, col)); wxGridCellEditor* editor = attr->GetEditor(this, row, col);
if ( !editor->IsCreated() ) if ( !editor->IsCreated() )
{ {
editor->Create(m_gridWin, -1, editor->Create(m_gridWin, -1,
@@ -5379,7 +5397,7 @@ void wxGrid::HideCellEditControl()
int col = m_currentCellCoords.GetCol(); int col = m_currentCellCoords.GetCol();
wxGridCellAttr* attr = GetCellAttr(row, col); wxGridCellAttr* attr = GetCellAttr(row, col);
attr->GetEditor(GetDefaultEditorForCell(row, col))->Show( FALSE ); attr->GetEditor(this, row, col)->Show( FALSE );
attr->DecRef(); attr->DecRef();
m_gridWin->SetFocus(); m_gridWin->SetFocus();
} }
@@ -5401,7 +5419,7 @@ void wxGrid::SaveEditControlValue()
int col = m_currentCellCoords.GetCol(); int col = m_currentCellCoords.GetCol();
wxGridCellAttr* attr = GetCellAttr(row, col); wxGridCellAttr* attr = GetCellAttr(row, col);
wxGridCellEditor* editor = attr->GetEditor(GetDefaultEditorForCell(row, col)); wxGridCellEditor* editor = attr->GetEditor(this, row, col);
bool changed = editor->EndEdit(row, col, TRUE, this); bool changed = editor->EndEdit(row, col, TRUE, this);
attr->DecRef(); attr->DecRef();
@@ -6334,12 +6352,12 @@ void wxGrid::GetDefaultCellAlignment( int *horiz, int *vert )
wxGridCellRenderer *wxGrid::GetDefaultRenderer() const wxGridCellRenderer *wxGrid::GetDefaultRenderer() const
{ {
return m_defaultCellAttr->GetRenderer(NULL); return m_defaultCellAttr->GetRenderer(NULL,0,0);
} }
wxGridCellEditor *wxGrid::GetDefaultEditor() const wxGridCellEditor *wxGrid::GetDefaultEditor() const
{ {
return m_defaultCellAttr->GetEditor(NULL); return m_defaultCellAttr->GetEditor(NULL,0,0);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -6380,7 +6398,7 @@ void wxGrid::GetCellAlignment( int row, int col, int *horiz, int *vert )
wxGridCellRenderer* wxGrid::GetCellRenderer(int row, int col) wxGridCellRenderer* wxGrid::GetCellRenderer(int row, int col)
{ {
wxGridCellAttr* attr = GetCellAttr(row, col); wxGridCellAttr* attr = GetCellAttr(row, col);
wxGridCellRenderer* renderer = attr->GetRenderer(GetDefaultRendererForCell(row,col)); wxGridCellRenderer* renderer = attr->GetRenderer(this, row, col);
attr->DecRef(); attr->DecRef();
return renderer; return renderer;
} }
@@ -6388,7 +6406,7 @@ wxGridCellRenderer* wxGrid::GetCellRenderer(int row, int col)
wxGridCellEditor* wxGrid::GetCellEditor(int row, int col) wxGridCellEditor* wxGrid::GetCellEditor(int row, int col)
{ {
wxGridCellAttr* attr = GetCellAttr(row, col); wxGridCellAttr* attr = GetCellAttr(row, col);
wxGridCellEditor* editor = attr->GetEditor(GetDefaultEditorForCell(row, col)); wxGridCellEditor* editor = attr->GetEditor(this, row, col);
attr->DecRef(); attr->DecRef();
return editor; return editor;
} }
@@ -6757,7 +6775,7 @@ void wxGrid::AutoSizeColumn( int col, bool setAsMin )
for ( int row = 0; row < m_numRows; row++ ) for ( int row = 0; row < m_numRows; row++ )
{ {
wxGridCellAttr* attr = GetCellAttr(row, col); wxGridCellAttr* attr = GetCellAttr(row, col);
wxGridCellRenderer* renderer = attr->GetRenderer(GetDefaultRendererForCell(row,col)); wxGridCellRenderer* renderer = attr->GetRenderer(this, row, col);
if ( renderer ) if ( renderer )
{ {
width = renderer->GetBestSize(*this, *attr, dc, row, col).x; width = renderer->GetBestSize(*this, *attr, dc, row, col).x;