Get rid of WXGetAsCustom().
Instead, have WXOnActivate() and WXOnLeftClick() with same signatures as their public API counterparts and just call Activate/LeftClick() from them for wxDataViewCustomRenderer. This accomplishes the same thing, but makes it easier to override behaviour in wx's internal implementations of renderers. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67093 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
1852bf0db5
commit
dbc3aec19a
@ -41,29 +41,24 @@ public:
|
||||
|
||||
// implementation
|
||||
|
||||
// this is a replacement for dynamic_cast<wxDataViewCustomRenderer> in the
|
||||
// code checking whether the renderer is interested in mouse events, it's
|
||||
// overridden in wxDataViewCustomRenderer to return the object itself but
|
||||
// intentionally returns NULL for all the other renderer classes as the
|
||||
// user should _not_ be able to override Activate/LeftClick() when deriving
|
||||
// from them for consistency with the other ports and while we can't
|
||||
// prevent this from working at compile-time because all renderers are
|
||||
// custom renderers in the generic implementation, we at least make sure
|
||||
// that it doesn't work at run-time because Activate/LeftClick() would
|
||||
// never be called
|
||||
virtual wxDataViewCustomRenderer *WXGetAsCustom() { return NULL; }
|
||||
// These callbacks are used by generic implementation of wxDVC itself.
|
||||
// They're different from the corresponding Activate/LeftClick() methods
|
||||
// which should only be overridable for the custom renderers while the
|
||||
// generic implementation uses these ones for all of them, including the
|
||||
// standard ones.
|
||||
|
||||
// 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),
|
||||
virtual bool WXOnActivate(wxRect WXUNUSED(cell),
|
||||
wxDataViewModel *WXUNUSED(model),
|
||||
const wxDataViewItem & WXUNUSED(item),
|
||||
unsigned int WXUNUSED(col))
|
||||
{
|
||||
}
|
||||
{ return false; }
|
||||
|
||||
virtual bool WXOnLeftClick(wxPoint WXUNUSED(cursor),
|
||||
wxRect WXUNUSED(cell),
|
||||
wxDataViewModel *WXUNUSED(model),
|
||||
const wxDataViewItem & WXUNUSED(item),
|
||||
unsigned int WXUNUSED(col) )
|
||||
{ return false; }
|
||||
|
||||
private:
|
||||
int m_align;
|
||||
|
@ -23,7 +23,25 @@ public:
|
||||
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
||||
int align = wxDVR_DEFAULT_ALIGNMENT );
|
||||
|
||||
virtual wxDataViewCustomRenderer *WXGetAsCustom() { return this; }
|
||||
|
||||
// see the explanation of the following WXOnXXX() methods in wx/generic/dvrenderer.h
|
||||
|
||||
virtual bool WXOnActivate(wxRect cell,
|
||||
wxDataViewModel *model,
|
||||
const wxDataViewItem& item,
|
||||
unsigned int col)
|
||||
{
|
||||
return Activate(cell, model, item, col);
|
||||
}
|
||||
|
||||
virtual bool WXOnLeftClick(wxPoint cursor,
|
||||
wxRect cell,
|
||||
wxDataViewModel *model,
|
||||
const wxDataViewItem &item,
|
||||
unsigned int col)
|
||||
{
|
||||
return LeftClick(cursor, cell, model, item, col);
|
||||
}
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
|
||||
@ -103,8 +121,8 @@ public:
|
||||
wxSize GetSize() const;
|
||||
|
||||
// Implementation only, don't use nor override
|
||||
virtual void WXOnActivate(wxDataViewModel *model,
|
||||
const wxVariant& valueOld,
|
||||
virtual bool WXOnActivate(wxRect cell,
|
||||
wxDataViewModel *model,
|
||||
const wxDataViewItem& item,
|
||||
unsigned int col);
|
||||
private:
|
||||
@ -187,8 +205,8 @@ public:
|
||||
virtual wxSize GetSize() const;
|
||||
|
||||
// Implementation only, don't use nor override
|
||||
virtual void WXOnActivate(wxDataViewModel *model,
|
||||
const wxVariant& valueOld,
|
||||
virtual bool WXOnActivate(wxRect cell,
|
||||
wxDataViewModel *model,
|
||||
const wxDataViewItem& item,
|
||||
unsigned int col);
|
||||
|
||||
|
@ -863,15 +863,18 @@ bool wxDataViewToggleRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxDataViewToggleRenderer::WXOnActivate(wxDataViewModel *model,
|
||||
const wxVariant& valueOld,
|
||||
const wxDataViewItem & item,
|
||||
bool wxDataViewToggleRenderer::WXOnActivate(wxRect WXUNUSED(cell),
|
||||
wxDataViewModel *model,
|
||||
const wxDataViewItem& item,
|
||||
unsigned int col)
|
||||
{
|
||||
if (model->IsEnabled(item, col))
|
||||
{
|
||||
model->ChangeValue(!valueOld.GetBool(), item, col);
|
||||
model->ChangeValue(!m_toggle, item, col);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
wxSize wxDataViewToggleRenderer::GetSize() const
|
||||
@ -1023,12 +1026,12 @@ wxSize wxDataViewDateRenderer::GetSize() const
|
||||
return GetTextExtent(m_date.FormatDate());
|
||||
}
|
||||
|
||||
void wxDataViewDateRenderer::WXOnActivate(wxDataViewModel *model,
|
||||
const wxVariant& valueOld,
|
||||
const wxDataViewItem & item,
|
||||
unsigned int col )
|
||||
bool wxDataViewDateRenderer::WXOnActivate(wxRect WXUNUSED(cell),
|
||||
wxDataViewModel *model,
|
||||
const wxDataViewItem& item,
|
||||
unsigned int col)
|
||||
{
|
||||
wxDateTime dtOld = valueOld.GetDateTime();
|
||||
wxDateTime dtOld = m_date;
|
||||
|
||||
#if wxUSE_DATE_RENDERER_POPUP
|
||||
wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient(
|
||||
@ -1040,6 +1043,8 @@ void wxDataViewDateRenderer::WXOnActivate(wxDataViewModel *model,
|
||||
#else // !wxUSE_DATE_RENDERER_POPUP
|
||||
wxMessageBox(dtOld.Format());
|
||||
#endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
@ -3630,19 +3635,11 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
|
||||
{
|
||||
const unsigned colIdx = col->GetModelColumn();
|
||||
|
||||
wxVariant value;
|
||||
model->GetValue( value, item, colIdx );
|
||||
cell->PrepareForItem(model, item, colIdx);
|
||||
|
||||
cell->WXOnActivate(model, value, item, colIdx);
|
||||
|
||||
if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
|
||||
{
|
||||
cell->PrepareForItem(model, item, colIdx);
|
||||
|
||||
wxRect cell_rect( xpos, GetLineStart( current ),
|
||||
col->GetWidth(), GetLineHeight( current ) );
|
||||
custom->Activate( cell_rect, model, item, colIdx );
|
||||
}
|
||||
wxRect cell_rect( xpos, GetLineStart( current ),
|
||||
col->GetWidth(), GetLineHeight( current ) );
|
||||
cell->WXOnActivate( cell_rect, model, item, colIdx );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3813,53 +3810,50 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
|
||||
// Call LeftClick after everything else as under GTK+
|
||||
if (cell->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE)
|
||||
{
|
||||
if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
|
||||
// notify cell about click
|
||||
cell->PrepareForItem(model, item, col->GetModelColumn());
|
||||
|
||||
wxRect cell_rect( xpos, GetLineStart( current ),
|
||||
col->GetWidth(), GetLineHeight( current ) );
|
||||
|
||||
// Report position relative to the cell's custom area, i.e.
|
||||
// no the entire space as given by the control but the one
|
||||
// used by the renderer after calculation of alignment etc.
|
||||
|
||||
// adjust the rectangle ourselves to account for the alignment
|
||||
wxRect rectItem = cell_rect;
|
||||
const int align = cell->GetAlignment();
|
||||
if ( align != wxDVR_DEFAULT_ALIGNMENT )
|
||||
{
|
||||
// notify cell about click
|
||||
custom->PrepareForItem(model, item, col->GetModelColumn());
|
||||
const wxSize size = cell->GetSize();
|
||||
|
||||
wxRect cell_rect( xpos, GetLineStart( current ),
|
||||
col->GetWidth(), GetLineHeight( current ) );
|
||||
|
||||
// Report position relative to the cell's custom area, i.e.
|
||||
// no the entire space as given by the control but the one
|
||||
// used by the renderer after calculation of alignment etc.
|
||||
|
||||
// adjust the rectangle ourselves to account for the alignment
|
||||
wxRect rectItem = cell_rect;
|
||||
const int align = custom->GetAlignment();
|
||||
if ( align != wxDVR_DEFAULT_ALIGNMENT )
|
||||
if ( size.x >= 0 && size.x < cell_rect.width )
|
||||
{
|
||||
const wxSize size = custom->GetSize();
|
||||
|
||||
if ( size.x >= 0 && size.x < cell_rect.width )
|
||||
{
|
||||
if ( align & wxALIGN_CENTER_HORIZONTAL )
|
||||
rectItem.x += (cell_rect.width - size.x)/2;
|
||||
else if ( align & wxALIGN_RIGHT )
|
||||
rectItem.x += cell_rect.width - size.x;
|
||||
// else: wxALIGN_LEFT is the default
|
||||
}
|
||||
|
||||
if ( size.y >= 0 && size.y < cell_rect.height )
|
||||
{
|
||||
if ( align & wxALIGN_CENTER_VERTICAL )
|
||||
rectItem.y += (cell_rect.height - size.y)/2;
|
||||
else if ( align & wxALIGN_BOTTOM )
|
||||
rectItem.y += cell_rect.height - size.y;
|
||||
// else: wxALIGN_TOP is the default
|
||||
}
|
||||
if ( align & wxALIGN_CENTER_HORIZONTAL )
|
||||
rectItem.x += (cell_rect.width - size.x)/2;
|
||||
else if ( align & wxALIGN_RIGHT )
|
||||
rectItem.x += cell_rect.width - size.x;
|
||||
// else: wxALIGN_LEFT is the default
|
||||
}
|
||||
|
||||
wxPoint pos( event.GetPosition() );
|
||||
pos.x -= rectItem.x;
|
||||
pos.y -= rectItem.y;
|
||||
|
||||
m_owner->CalcUnscrolledPosition( pos.x, pos.y, &pos.x, &pos.y );
|
||||
|
||||
/* ignore ret */ custom->LeftClick( pos, cell_rect,
|
||||
model, item, col->GetModelColumn());
|
||||
if ( size.y >= 0 && size.y < cell_rect.height )
|
||||
{
|
||||
if ( align & wxALIGN_CENTER_VERTICAL )
|
||||
rectItem.y += (cell_rect.height - size.y)/2;
|
||||
else if ( align & wxALIGN_BOTTOM )
|
||||
rectItem.y += cell_rect.height - size.y;
|
||||
// else: wxALIGN_TOP is the default
|
||||
}
|
||||
}
|
||||
|
||||
wxPoint pos( event.GetPosition() );
|
||||
pos.x -= rectItem.x;
|
||||
pos.y -= rectItem.y;
|
||||
|
||||
m_owner->CalcUnscrolledPosition( pos.x, pos.y, &pos.x, &pos.y );
|
||||
|
||||
/* ignore ret */ cell->WXOnLeftClick( pos, cell_rect,
|
||||
model, item, col->GetModelColumn());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user