Fix activation handling in generic wxDataViewCtrl renderers.

Handling of activation in the generic implementation of standard renderers was
broken since r62589 which stopped calling their Activate() method. Restore it
by introducing a special WXOnActivate() replacing it (but clearly marked as
private and implementation-only) and calling it instead.

Closes #11460.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64654 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-06-20 17:43:30 +00:00
parent ed0a9eca57
commit 6218600646
3 changed files with 46 additions and 24 deletions

View File

@@ -47,12 +47,24 @@ public:
// intentionally returns NULL for all the other renderer classes as the // intentionally returns NULL for all the other renderer classes as the
// user should _not_ be able to override Activate/LeftClick() when deriving // user should _not_ be able to override Activate/LeftClick() when deriving
// from them for consistency with the other ports and while we can't // from them for consistency with the other ports and while we can't
// prevent this from working at compile-time because all renderer are // prevent this from working at compile-time because all renderers are
// custom renderers in the generic implementation, we at least make sure // custom renderers in the generic implementation, we at least make sure
// that it doesn't work at run-time because Activate/LeftClick() would // that it doesn't work at run-time because Activate/LeftClick() would
// never be called // never be called
virtual wxDataViewCustomRenderer *WXGetAsCustom() { return NULL; } virtual wxDataViewCustomRenderer *WXGetAsCustom() { return NULL; }
// The generic implementation of some standard renderers reacts to item
// activation, so provide this internal function which is called by
// wxDataViewCtrl for them. It is called with the old value of the cell and
// is passed the model and cell coordinates to be able to change the model
// value for this cell.
virtual void WXOnActivate(wxDataViewModel * WXUNUSED(model),
const wxVariant& WXUNUSED(valueOld),
const wxDataViewItem& WXUNUSED(item),
unsigned int WXUNUSED(col))
{
}
private: private:
int m_align; int m_align;
wxDataViewCellMode m_mode; wxDataViewCellMode m_mode;

View File

@@ -100,10 +100,13 @@ public:
bool GetValue( wxVariant &value ) const; bool GetValue( wxVariant &value ) const;
bool Render( wxRect cell, wxDC *dc, int state ); bool Render( wxRect cell, wxDC *dc, int state );
bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
unsigned int col );
wxSize GetSize() const; wxSize GetSize() const;
// Implementation only, don't use nor override
virtual void WXOnActivate(wxDataViewModel *model,
const wxVariant& valueOld,
const wxDataViewItem& item,
unsigned int col);
private: private:
bool m_toggle; bool m_toggle;
@@ -182,10 +185,12 @@ public:
virtual bool Render( wxRect cell, wxDC *dc, int state ); virtual bool Render( wxRect cell, wxDC *dc, int state );
virtual wxSize GetSize() const; virtual wxSize GetSize() const;
virtual bool Activate( wxRect cell,
wxDataViewModel *model, // Implementation only, don't use nor override
virtual void WXOnActivate(wxDataViewModel *model,
const wxVariant& valueOld,
const wxDataViewItem& item, const wxDataViewItem& item,
unsigned int col ); unsigned int col);
private: private:
wxDateTime m_date; wxDateTime m_date;

View File

@@ -844,12 +844,12 @@ bool wxDataViewToggleRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state
return true; return true;
} }
bool wxDataViewToggleRenderer::Activate( wxRect WXUNUSED(cell), void wxDataViewToggleRenderer::WXOnActivate(wxDataViewModel *model,
wxDataViewModel *model, const wxVariant& valueOld,
const wxDataViewItem & item, unsigned int col) const wxDataViewItem & item,
unsigned int col)
{ {
model->ChangeValue(!m_toggle, item, col); model->ChangeValue(!valueOld.GetBool(), item, col);
return true;
} }
wxSize wxDataViewToggleRenderer::GetSize() const wxSize wxDataViewToggleRenderer::GetSize() const
@@ -1005,24 +1005,23 @@ wxSize wxDataViewDateRenderer::GetSize() const
return wxSize(x,y+d); return wxSize(x,y+d);
} }
bool wxDataViewDateRenderer::Activate( wxRect WXUNUSED(cell), wxDataViewModel *model, void wxDataViewDateRenderer::WXOnActivate(wxDataViewModel *model,
const wxDataViewItem & item, unsigned int col ) const wxVariant& valueOld,
const wxDataViewItem & item,
unsigned int col )
{ {
wxVariant variant; wxDateTime dtOld = valueOld.GetDateTime();
model->GetValue( variant, item, col );
wxDateTime value = variant.GetDateTime();
#if wxUSE_DATE_RENDERER_POPUP #if wxUSE_DATE_RENDERER_POPUP
wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient( wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient(
GetOwner()->GetOwner()->GetParent(), &value, model, item, col); GetOwner()->GetOwner()->GetParent(), &dtOld, model, item, col);
wxPoint pos = wxGetMousePosition(); wxPoint pos = wxGetMousePosition();
popup->Move( pos ); popup->Move( pos );
popup->Layout(); popup->Layout();
popup->Popup( popup->m_cal ); popup->Popup( popup->m_cal );
#else // !wxUSE_DATE_RENDERER_POPUP #else // !wxUSE_DATE_RENDERER_POPUP
wxMessageBox(value.Format()); wxMessageBox(dtOld.Format());
#endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
return true;
} }
// --------------------------------------------------------- // ---------------------------------------------------------
@@ -3585,14 +3584,20 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
{ {
if ((!ignore_other_columns) && (cell->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE)) if ((!ignore_other_columns) && (cell->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE))
{ {
const unsigned colIdx = col->GetModelColumn();
wxVariant value;
model->GetValue( value, item, colIdx );
cell->WXOnActivate(model, value, item, colIdx);
if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() ) if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
{ {
wxVariant value; cell->SetValue( value );
model->GetValue( value, item, col->GetModelColumn() );
custom->SetValue( value );
wxRect cell_rect( xpos, GetLineStart( current ), wxRect cell_rect( xpos, GetLineStart( current ),
col->GetWidth(), GetLineHeight( current ) ); col->GetWidth(), GetLineHeight( current ) );
custom->Activate( cell_rect, model, item, col->GetModelColumn() ); custom->Activate( cell_rect, model, item, colIdx );
} }
} }
else else