X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a6f1201f979564c4fe025cb31f0cf65517d850f1..205bdf2069b93743848d69a39c0bd4a32e9ff8b7:/src/generic/datavgen.cpp diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index d407c82285..bdeadffd36 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -634,22 +634,35 @@ wxDataViewRenderer::RenderWithAttr(wxDC& dc, { const wxSize size = GetSize(); - // horizontal alignment: - if (align & wxALIGN_CENTER_HORIZONTAL) - item_rect.x = cell_rect.x + (cell_rect.width / 2) - (size.x / 2); - else if (align & wxALIGN_RIGHT) - item_rect.x = cell_rect.x + cell_rect.width - size.x; - // else: wxALIGN_LEFT is the default + // 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 < cell_rect.width ) + { + if (align & wxALIGN_CENTER_HORIZONTAL) + item_rect.x += (cell_rect.width - size.x)/2; + else if (align & wxALIGN_RIGHT) + item_rect.x += cell_rect.width - size.x; + // else: wxALIGN_LEFT is the default + + item_rect.width = size.x; + } - // vertical alignment: - item_rect.y = cell_rect.y; - if (align & wxALIGN_CENTER_VERTICAL) - item_rect.y = cell_rect.y + (cell_rect.height / 2) - (size.y / 2); - else if (align & wxALIGN_BOTTOM) - item_rect.y = cell_rect.y + cell_rect.height - size.y; - // else: wxALIGN_TOP is the default + if ( size.y < cell_rect.height ) + { + if (align & wxALIGN_CENTER_VERTICAL) + item_rect.y += (cell_rect.height - size.y)/2; + else if (align & wxALIGN_BOTTOM) + item_rect.y += cell_rect.height - size.y; + // else: wxALIGN_TOP is the default - item_rect.SetSize(size); + item_rect.height = size.y; + } } return Render(item_rect, &dc, state); @@ -704,30 +717,24 @@ wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, { } -void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, - wxRect cell, wxDC *dc, int state ) -{ - wxColour col = state & wxDATAVIEW_CELL_SELECTED - ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) - : GetOwner()->GetOwner()->GetForegroundColour(); - - wxDataViewItemAttr attr; - attr.SetColour(col); - RenderText(*dc, cell, wxALIGN_NOT, text, &attr, state, xoffset); -} - void wxDataViewCustomRenderer::RenderText(wxDC& dc, const wxRect& rect, int align, const wxString& text, const wxDataViewItemAttr *attr, - int WXUNUSED(state), + int state, int xoffset) { - wxDCTextColourChanger changeFg(dc); + wxColour col; if ( attr && attr->HasColour() ) - changeFg.Set(attr->GetColour()); + col = attr->GetColour(); + else if ( state & wxDATAVIEW_CELL_SELECTED ) + col = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); + else // use default foreground + col = GetOwner()->GetOwner()->GetForegroundColour(); + + wxDCTextColourChanger changeFg(dc, col); wxDCFontChanger changeFont(dc); if ( attr && attr->HasFont() ) @@ -938,10 +945,6 @@ wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label, m_value = 0; } -wxDataViewProgressRenderer::~wxDataViewProgressRenderer() -{ -} - bool wxDataViewProgressRenderer::SetValue( const wxVariant &value ) { m_value = (long) value; @@ -958,18 +961,24 @@ bool wxDataViewProgressRenderer::GetValue( wxVariant &value ) const return true; } -bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) ) +bool wxDataViewProgressRenderer::RenderWithAttr(wxDC& dc, + const wxRect& rect, + int WXUNUSED(align), + const wxDataViewItemAttr *attr, + int WXUNUSED(state)) { - double pct = (double)m_value / 100.0; - wxRect bar = cell; - bar.width = (int)(cell.width * pct); - dc->SetPen( *wxTRANSPARENT_PEN ); - dc->SetBrush( *wxBLUE_BRUSH ); - dc->DrawRectangle( bar ); + // deflat the rect to leave a small border between bars in adjacent rows + wxRect bar = rect.Deflate(0, 1); - dc->SetBrush( *wxTRANSPARENT_BRUSH ); - dc->SetPen( *wxBLACK_PEN ); - dc->DrawRectangle( cell ); + dc.SetBrush( *wxTRANSPARENT_BRUSH ); + dc.SetPen( *wxBLACK_PEN ); + dc.DrawRectangle( bar ); + + bar.width = (int)(bar.width * m_value / 100.); + dc.SetPen( *wxTRANSPARENT_PEN ); + dc.SetBrush( attr && attr->HasColour() ? wxBrush(attr->GetColour()) + : *wxBLUE_BRUSH ); + dc.DrawRectangle( bar ); return true; } @@ -1106,10 +1115,6 @@ const wxString &varianttype, wxDataViewCellMode mode, int align ) : SetAlignment(align); } -wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer() -{ -} - bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value ) { m_value << value; @@ -1121,17 +1126,23 @@ bool wxDataViewIconTextRenderer::GetValue( wxVariant& WXUNUSED(value) ) const return false; } -bool wxDataViewIconTextRenderer::Render( wxRect cell, wxDC *dc, int state ) +bool +wxDataViewIconTextRenderer::RenderWithAttr(wxDC& dc, + const wxRect& rect, + int align, + const wxDataViewItemAttr *attr, + int state) { int xoffset = 0; - const wxIcon &icon = m_value.GetIcon(); - if (icon.IsOk()) + + const wxIcon& icon = m_value.GetIcon(); + if ( icon.IsOk() ) { - dc->DrawIcon( icon, cell.x, cell.y + ((cell.height - icon.GetHeight()) / 2)); - xoffset = icon.GetWidth()+4; + dc.DrawIcon(icon, rect.x, rect.y + (rect.height - icon.GetHeight())/2); + xoffset = icon.GetWidth()+4; } - RenderText( m_value.GetText(), xoffset, cell, dc, state ); + RenderText(dc, rect, align, m_value.GetText(), attr, state, xoffset); return true; }