setting parameters for wxGridCellFloatRenderer seems to work

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6358 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-02-29 19:30:26 +00:00
parent 0b190b0f6a
commit e72b421324
2 changed files with 53 additions and 12 deletions

View File

@@ -131,6 +131,9 @@ public:
// left to the derived classes // left to the derived classes
virtual void SetParameters(const wxString& params); virtual void SetParameters(const wxString& params);
// create a new object which is the copy of this one
virtual wxGridCellRenderer *Clone() const = 0;
protected: protected:
// virtual dtor for any base class - private because only DecRef() can // virtual dtor for any base class - private because only DecRef() can
// delete us // delete us
@@ -162,6 +165,9 @@ public:
wxDC& dc, wxDC& dc,
int row, int col); int row, int col);
virtual wxGridCellRenderer *Clone() const
{ return new wxGridCellStringRenderer; }
protected: protected:
// set the text colours before drawing // set the text colours before drawing
void SetTextColoursAndFont(wxGrid& grid, void SetTextColoursAndFont(wxGrid& grid,
@@ -192,6 +198,9 @@ public:
wxDC& dc, wxDC& dc,
int row, int col); int row, int col);
virtual wxGridCellRenderer *Clone() const
{ return new wxGridCellNumberRenderer; }
protected: protected:
wxString GetString(wxGrid& grid, int row, int col); wxString GetString(wxGrid& grid, int row, int col);
}; };
@@ -223,6 +232,8 @@ public:
// parameters string format is "width[,precision]" // parameters string format is "width[,precision]"
virtual void SetParameters(const wxString& params); virtual void SetParameters(const wxString& params);
virtual wxGridCellRenderer *Clone() const;
protected: protected:
wxString GetString(wxGrid& grid, int row, int col); wxString GetString(wxGrid& grid, int row, int col);
@@ -252,6 +263,9 @@ public:
wxDC& dc, wxDC& dc,
int row, int col); int row, int col);
virtual wxGridCellRenderer *Clone() const
{ return new wxGridCellBoolRenderer; }
private: private:
static wxSize ms_sizeCheckMark; static wxSize ms_sizeCheckMark;
}; };

View File

@@ -1216,6 +1216,16 @@ wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width, int precision)
SetPrecision(precision); SetPrecision(precision);
} }
wxGridCellRenderer *wxGridCellFloatRenderer::Clone() const
{
wxGridCellFloatRenderer *renderer = new wxGridCellFloatRenderer;
renderer->m_width = m_width;
renderer->m_precision = m_precision;
renderer->m_format = m_format;
return renderer;
}
wxString wxGridCellFloatRenderer::GetString(wxGrid& grid, int row, int col) wxString wxGridCellFloatRenderer::GetString(wxGrid& grid, int row, int col)
{ {
wxGridTableBase *table = grid.GetTable(); wxGridTableBase *table = grid.GetTable();
@@ -6937,11 +6947,17 @@ wxGrid::GetDefaultEditorForType(const wxString& typeName) const
wxGridCellRenderer* wxGridCellRenderer*
wxGrid::GetDefaultRendererForType(const wxString& typeName) const wxGrid::GetDefaultRendererForType(const wxString& typeName) const
{ {
// first try to find an exact match
wxGridCellRenderer *renderer;
int index = m_typeRegistry->FindDataType(typeName);
if ( index == wxNOT_FOUND )
{
// then try to construct a renderer from the base name and parameters
// following it
// the first part of the typename is the "real" type, anything after ':' // the first part of the typename is the "real" type, anything after ':'
// are the parameters for the renderer // are the parameters for the renderer
wxString type = typeName.BeforeFirst(_T(':')); index = m_typeRegistry->FindDataType(typeName.BeforeFirst(_T(':')));
int index = m_typeRegistry->FindDataType(type);
if ( index == wxNOT_FOUND ) if ( index == wxNOT_FOUND )
{ {
wxFAIL_MSG(wxT("Unknown data type name")); wxFAIL_MSG(wxT("Unknown data type name"));
@@ -6949,11 +6965,22 @@ wxGrid::GetDefaultRendererForType(const wxString& typeName) const
return NULL; return NULL;
} }
wxGridCellRenderer *renderer = m_typeRegistry->GetRenderer(index); renderer = m_typeRegistry->GetRenderer(index);
wxGridCellRenderer *rendererOld = renderer;
renderer = renderer->Clone();
rendererOld->DecRef();
// do it even if there are no parameters to reset them to defaults // do it even if there are no parameters to reset them to defaults
renderer->SetParameters(typeName.AfterFirst(_T(':'))); renderer->SetParameters(typeName.AfterFirst(_T(':')));
// register the new typename
m_typeRegistry->RegisterDataType(typeName, renderer, NULL);
}
else
{
renderer = m_typeRegistry->GetRenderer(index);
}
return renderer; return renderer;
} }