+ if ( isValid && event.IsAllowed() )
+ {
+ dv_ctrl->GetModel()->ChangeValue(value, m_item, col);
+ return true;
+ }
+
+ return false;
+}
+
+void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel *model,
+ const wxDataViewItem& item,
+ unsigned column)
+{
+ wxVariant value;
+ model->GetValue(value, item, column);
+ SetValue(value);
+
+ wxDataViewItemAttr attr;
+ model->GetAttr(item, column, attr);
+ SetAttr(attr);
+
+ SetEnabled(model->IsEnabled(item, column));
+}
+
+
+// ----------------------------------------------------------------------------
+// wxDataViewCustomRendererBase
+// ----------------------------------------------------------------------------
+
+bool wxDataViewCustomRendererBase::ActivateCell(const wxRect& cell,
+ wxDataViewModel *model,
+ const wxDataViewItem & item,
+ unsigned int col,
+ const wxMouseEvent* mouseEvent)
+{
+ // Compatibility code
+ if ( mouseEvent )
+ return LeftClick(mouseEvent->GetPosition(), cell, model, item, col);
+ else
+ return Activate(cell, model, item, col);
+}
+
+void wxDataViewCustomRendererBase::RenderBackground(wxDC* dc, const wxRect& rect)
+{
+ if ( !m_attr.HasBackgroundColour() )
+ return;
+
+ const wxColour& colour = m_attr.GetBackgroundColour();
+ wxDCPenChanger changePen(*dc, colour);
+ wxDCBrushChanger changeBrush(*dc, colour);
+
+ dc->DrawRectangle(rect);
+}
+
+void
+wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell, wxDC *dc, int state)
+{
+ wxCHECK_RET( dc, "no DC to draw on in custom renderer?" );
+
+ // adjust the rectangle ourselves to account for the alignment
+ wxRect rectItem = rectCell;
+ const int align = GetAlignment();
+ if ( align != wxDVR_DEFAULT_ALIGNMENT )
+ {
+ const wxSize size = GetSize();
+
+ // take alignment into account only if there is enough space, otherwise
+ // show as much contents as possible
+ //
+ // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
+ // return hard-coded size which can be more than they need and if we
+ // trusted their GetSize() we'd draw the text out of cell bounds
+ // entirely
+
+ if ( size.x >= 0 && size.x < rectCell.width )
+ {
+ if ( align & wxALIGN_CENTER_HORIZONTAL )
+ rectItem.x += (rectCell.width - size.x)/2;
+ else if ( align & wxALIGN_RIGHT )
+ rectItem.x += rectCell.width - size.x;
+ // else: wxALIGN_LEFT is the default
+
+ rectItem.width = size.x;
+ }
+
+ if ( size.y >= 0 && size.y < rectCell.height )
+ {
+ if ( align & wxALIGN_CENTER_VERTICAL )
+ rectItem.y += (rectCell.height - size.y)/2;
+ else if ( align & wxALIGN_BOTTOM )
+ rectItem.y += rectCell.height - size.y;
+ // else: wxALIGN_TOP is the default
+
+ rectItem.height = size.y;
+ }
+ }
+
+
+ // set up the DC attributes
+
+ // override custom foreground with the standard one for the selected items
+ // because we currently don't allow changing the selection background and
+ // custom colours may be unreadable on it
+ wxColour col;
+ if ( state & wxDATAVIEW_CELL_SELECTED )
+ col = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
+ else if ( m_attr.HasColour() )
+ col = m_attr.GetColour();
+ else // use default foreground
+ col = GetOwner()->GetOwner()->GetForegroundColour();
+
+ wxDCTextColourChanger changeFg(*dc, col);
+
+ wxDCFontChanger changeFont(*dc);
+ if ( m_attr.HasFont() )
+ changeFont.Set(m_attr.GetEffectiveFont(dc->GetFont()));
+
+ Render(rectItem, dc, state);
+}
+
+wxSize wxDataViewCustomRendererBase::GetTextExtent(const wxString& str) const
+{
+ const wxDataViewCtrl *view = GetView();
+
+ if ( m_attr.HasFont() )
+ {
+ wxFont font(m_attr.GetEffectiveFont(view->GetFont()));
+ wxSize size;
+ view->GetTextExtent(str, &size.x, &size.y, NULL, NULL, &font);
+ return size;
+ }
+ else
+ {
+ return view->GetTextExtent(str);
+ }
+}
+
+void
+wxDataViewCustomRendererBase::RenderText(const wxString& text,
+ int xoffset,
+ wxRect rect,
+ wxDC *dc,
+ int WXUNUSED(state))
+{
+ wxRect rectText = rect;
+ rectText.x += xoffset;
+ rectText.width -= xoffset;
+
+ // check if we want to ellipsize the text if it doesn't fit
+ wxString ellipsizedText;
+ if ( GetEllipsizeMode() != wxELLIPSIZE_NONE )
+ {
+ ellipsizedText = wxControl::Ellipsize
+ (
+ text,
+ *dc,
+ GetEllipsizeMode(),
+ rectText.width,
+ wxELLIPSIZE_FLAGS_NONE
+ );
+ }
+
+ // get the alignment to use
+ int align = GetAlignment();
+ if ( align == wxDVR_DEFAULT_ALIGNMENT )
+ {
+ // if we don't have an explicit alignment ourselves, use that of the
+ // column in horizontal direction and default vertical alignment
+ align = GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL;
+ }
+
+ dc->DrawLabel(ellipsizedText.empty() ? text : ellipsizedText,
+ rectText, align);