Merge branch 'shared-client-data'

Allow sharing client data in wxGrid-related classes.

See #22369.
This commit is contained in:
Vadim Zeitlin
2022-05-01 02:55:36 +02:00
11 changed files with 402 additions and 160 deletions

View File

@@ -253,6 +253,11 @@ int wxGridColumnOperations::GetFirstLine(const wxGrid *grid, wxGridWindow *gridW
// wxGridCellRenderer and wxGridCellEditor managing ref counting
// ----------------------------------------------------------------------------
wxGridCellWorker::wxGridCellWorker(const wxGridCellWorker& other)
{
CopyClientDataContainer(other);
}
void wxGridCellWorker::SetParameters(const wxString& WXUNUSED(params))
{
// nothing to do
@@ -445,6 +450,8 @@ wxGridCellAttr *wxGridCellAttr::Clone() const
m_editor->IncRef();
}
attr->CopyClientDataContainer(*this);
if ( IsReadOnly() )
attr->SetReadOnly();
@@ -485,6 +492,10 @@ void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom)
m_editor = mergefrom->m_editor;
m_editor->IncRef();
}
if ( !HasClientDataContainer() && mergefrom->HasClientDataContainer() )
{
CopyClientDataContainer(*mergefrom);
}
if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() )
SetReadOnly(mergefrom->IsReadOnly());

View File

@@ -158,6 +158,7 @@ using namespace wxGridPrivate;
// Enables a grid cell to display a formatted date
wxGridCellDateRenderer::wxGridCellDateRenderer(const wxString& outformat)
: wxGridCellStringRenderer()
{
if ( outformat.empty() )
{
@@ -170,11 +171,6 @@ wxGridCellDateRenderer::wxGridCellDateRenderer(const wxString& outformat)
m_tz = wxDateTime::Local;
}
wxGridCellRenderer *wxGridCellDateRenderer::Clone() const
{
return new wxGridCellDateRenderer(*this);
}
wxString wxGridCellDateRenderer::GetString(const wxGrid& grid, int row, int col)
{
wxString text;
@@ -256,11 +252,6 @@ wxGridCellDateTimeRenderer::wxGridCellDateTimeRenderer(const wxString& outformat
{
}
wxGridCellRenderer *wxGridCellDateTimeRenderer::Clone() const
{
return new wxGridCellDateTimeRenderer(*this);
}
void
wxGridCellDateTimeRenderer::GetDateParseParams(DateParseParams& params) const
{
@@ -273,6 +264,19 @@ wxGridCellDateTimeRenderer::GetDateParseParams(DateParseParams& params) const
// wxGridCellChoiceRenderer
// ----------------------------------------------------------------------------
wxGridCellChoiceRenderer::wxGridCellChoiceRenderer(const wxString& choices)
: wxGridCellStringRenderer()
{
if (!choices.empty())
SetParameters(choices);
}
wxGridCellChoiceRenderer::wxGridCellChoiceRenderer(const wxGridCellChoiceRenderer& other)
: wxGridCellStringRenderer(other),
m_choices(other.m_choices)
{
}
wxSize wxGridCellChoiceRenderer::GetMaxBestSize(wxGrid& WXUNUSED(grid),
wxGridCellAttr& attr,
wxDC& dc)
@@ -308,19 +312,6 @@ void wxGridCellChoiceRenderer::SetParameters(const wxString& params)
// eg data in cell is 0,1,2 ... n the cell could be rendered as "John","Fred"..."Bob"
wxGridCellEnumRenderer::wxGridCellEnumRenderer(const wxString& choices)
{
if (!choices.empty())
SetParameters(choices);
}
wxGridCellRenderer *wxGridCellEnumRenderer::Clone() const
{
wxGridCellEnumRenderer *renderer = new wxGridCellEnumRenderer;
renderer->m_choices = m_choices;
return renderer;
}
wxString wxGridCellEnumRenderer::GetString(const wxGrid& grid, int row, int col)
{
wxGridTableBase *table = grid.GetTable();
@@ -809,23 +800,13 @@ void wxGridCellNumberRenderer::SetParameters(const wxString& params)
wxGridCellFloatRenderer::wxGridCellFloatRenderer(int width,
int precision,
int format)
: wxGridCellStringRenderer()
{
SetWidth(width);
SetPrecision(precision);
SetFormat(format);
}
wxGridCellRenderer *wxGridCellFloatRenderer::Clone() const
{
wxGridCellFloatRenderer *renderer = new wxGridCellFloatRenderer;
renderer->m_width = m_width;
renderer->m_precision = m_precision;
renderer->m_style = m_style;
renderer->m_format = m_format;
return renderer;
}
wxString wxGridCellFloatRenderer::GetString(const wxGrid& grid, int row, int col)
{
wxGridTableBase *table = grid.GetTable();

View File

@@ -228,10 +228,14 @@ void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event)
// wxGridCellEditor
// ----------------------------------------------------------------------------
wxGridCellEditor::wxGridCellEditor()
wxGridCellEditor::wxGridCellEditor(const wxGridCellEditor& other)
: wxGridCellWorker(other),
m_control(other.m_control),
m_colFgOld(other.m_colFgOld),
m_colBgOld(other.m_colBgOld),
m_fontOld(other.m_fontOld)
{
m_control = NULL;
m_attr = NULL;
m_attr = other.m_attr ? other.m_attr->Clone() : NULL;
}
wxGridCellEditor::~wxGridCellEditor()
@@ -434,9 +438,17 @@ void wxGridCellEditor::StartingClick()
// wxGridCellTextEditor
// ----------------------------------------------------------------------------
wxGridCellTextEditor::wxGridCellTextEditor(size_t maxChars)
wxGridCellTextEditor::wxGridCellTextEditor(const wxGridCellTextEditor& other)
: wxGridCellEditor(other),
m_maxChars(other.m_maxChars),
m_value(other.m_value)
{
m_maxChars = maxChars;
#if wxUSE_VALIDATORS
if ( other.m_validator )
{
SetValidator(*other.m_validator);
}
#endif
}
void wxGridCellTextEditor::Create(wxWindow* parent,
@@ -669,18 +681,6 @@ void wxGridCellTextEditor::SetValidator(const wxValidator& validator)
}
#endif
wxGridCellEditor *wxGridCellTextEditor::Clone() const
{
wxGridCellTextEditor* editor = new wxGridCellTextEditor(m_maxChars);
#if wxUSE_VALIDATORS
if ( m_validator )
{
editor->SetValidator(*m_validator);
}
#endif
return editor;
}
// return the value in the text control
wxString wxGridCellTextEditor::GetValue() const
{
@@ -691,12 +691,6 @@ wxString wxGridCellTextEditor::GetValue() const
// wxGridCellNumberEditor
// ----------------------------------------------------------------------------
wxGridCellNumberEditor::wxGridCellNumberEditor(int min, int max)
{
m_min = min;
m_max = max;
}
void wxGridCellNumberEditor::Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler)
@@ -964,15 +958,6 @@ wxString wxGridCellNumberEditor::GetValue() const
// wxGridCellFloatEditor
// ----------------------------------------------------------------------------
wxGridCellFloatEditor::wxGridCellFloatEditor(int width,
int precision,
int format)
{
m_width = width;
m_precision = precision;
m_style = format;
}
void wxGridCellFloatEditor::Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler)
@@ -1486,15 +1471,11 @@ void wxGridCellBoolEditor::SetGridFromValue(int row, int col, wxGrid* grid) cons
// wxGridCellChoiceEditor
// ----------------------------------------------------------------------------
wxGridCellChoiceEditor::wxGridCellChoiceEditor(const wxArrayString& choices,
bool allowOthers)
: m_choices(choices),
m_allowOthers(allowOthers) { }
wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count,
const wxString choices[],
bool allowOthers)
: m_allowOthers(allowOthers)
: wxGridCellEditor(),
m_allowOthers(allowOthers)
{
if ( count )
{
@@ -1506,15 +1487,6 @@ wxGridCellChoiceEditor::wxGridCellChoiceEditor(size_t count,
}
}
wxGridCellEditor *wxGridCellChoiceEditor::Clone() const
{
wxGridCellChoiceEditor *editor = new wxGridCellChoiceEditor;
editor->m_allowOthers = m_allowOthers;
editor->m_choices = m_choices;
return editor;
}
void wxGridCellChoiceEditor::Create(wxWindow* parent,
wxWindowID id,
wxEvtHandler* evtHandler)
@@ -1684,21 +1656,13 @@ void wxGridCellChoiceEditor::OnComboCloseUp(wxCommandEvent& WXUNUSED(evt))
// "John","Fred"..."Bob" in the combo choice box
wxGridCellEnumEditor::wxGridCellEnumEditor(const wxString& choices)
:wxGridCellChoiceEditor()
: wxGridCellChoiceEditor(),
m_index(-1)
{
m_index = -1;
if (!choices.empty())
SetParameters(choices);
}
wxGridCellEditor *wxGridCellEnumEditor::Clone() const
{
wxGridCellEnumEditor *editor = new wxGridCellEnumEditor();
editor->m_index = m_index;
return editor;
}
void wxGridCellEnumEditor::BeginEdit(int row, int col, wxGrid* grid)
{
wxASSERT_MSG(m_control,
@@ -1846,6 +1810,7 @@ struct wxGridCellDateEditorKeyHandler
#endif // __WXGTK__
wxGridCellDateEditor::wxGridCellDateEditor(const wxString& format)
: wxGridCellEditor()
{
SetParameters(format);
}
@@ -1957,11 +1922,6 @@ void wxGridCellDateEditor::Reset()
m_value = DatePicker()->GetValue();
}
wxGridCellEditor *wxGridCellDateEditor::Clone() const
{
return new wxGridCellDateEditor(m_format);
}
wxString wxGridCellDateEditor::GetValue() const
{
wxASSERT_MSG(m_control, "The wxGridCellDateEditor must be created first!");