Applied patch [ 615769 ] generic wxListCtrl enhancements
implemented a couple of things missing from the generic wxListCtrl class which make it more similar to the Windows port 1) implemented wxLIST_FORMAT_RIGHT and wxLIST_FORMAT_CENTER 2) added an ellipsis (...) to the end of the string and shortened the string to fit inside the allowed width 3) left a margin of 8 pixels between columns so that the text is not shoved right together Note this is my first patch to wxWindows. I did read the patch howto and I think I got it right but please feel free to bother me about any discrepancies. In addition, I am not sure if the way I implemented the new routine to handle the formatting is adequate performance wise but it doesn't seem to slow things down too badly on my machine... :-) In addition, if this routine is accepted, it could also be used for the header data as well -- thoughts? Anthony Tuininga git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17437 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -421,6 +421,10 @@ private:
|
||||
const wxListItemAttr *attr,
|
||||
bool highlight);
|
||||
|
||||
// draw the text on the DC with the correct justification; also add an
|
||||
// ellipsis if the text is too large to fit in the current width
|
||||
void DrawTextFormatted(wxDC *dc, const wxString &text, int col, int x, int y, int width);
|
||||
|
||||
// these are only used by GetImage/SetImage above, we don't support images
|
||||
// with subitems at the public API level yet
|
||||
void SetImage( int index, int image );
|
||||
@@ -1738,15 +1742,69 @@ void wxListLineData::DrawInReportMode( wxDC *dc,
|
||||
width -= ix;
|
||||
}
|
||||
|
||||
wxDCClipper clipper(*dc, xOld, y, width, rect.height);
|
||||
wxDCClipper clipper(*dc, xOld, y, width - 8, rect.height);
|
||||
|
||||
if ( item->HasText() )
|
||||
{
|
||||
dc->DrawText( item->GetText(), xOld, y );
|
||||
DrawTextFormatted(dc, item->GetText(), col, xOld, y, width - 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxListLineData::DrawTextFormatted( wxDC *dc,
|
||||
const wxString &text,
|
||||
int col,
|
||||
int x,
|
||||
int y,
|
||||
int width )
|
||||
{
|
||||
wxString drawntext, ellipsis;
|
||||
wxCoord w, h, base_w;
|
||||
wxListItem item;
|
||||
|
||||
// determine if the string can fit inside the current width
|
||||
dc->GetTextExtent(text, &w, &h);
|
||||
|
||||
// if it can, draw it
|
||||
if (w <= width) {
|
||||
m_owner->GetColumn(col, item);
|
||||
if (item.m_format == wxLIST_FORMAT_LEFT)
|
||||
dc->DrawText(text, x, y);
|
||||
else if (item.m_format == wxLIST_FORMAT_RIGHT)
|
||||
dc->DrawText(text, x + width - w, y);
|
||||
else if (item.m_format == wxLIST_FORMAT_CENTER)
|
||||
dc->DrawText(text, x + ((width - w) / 2), y);
|
||||
|
||||
// otherwise, truncate and add an ellipsis if possible
|
||||
} else {
|
||||
|
||||
// determine the base width
|
||||
ellipsis = wxString(wxT("..."));
|
||||
dc->GetTextExtent(ellipsis, &base_w, &h);
|
||||
|
||||
// continue until we have enough space or only one character left
|
||||
drawntext = text.Left(text.Length() - 1);
|
||||
while (drawntext.Length() > 1) {
|
||||
dc->GetTextExtent(drawntext, &w, &h);
|
||||
if (w + base_w <= width)
|
||||
break;
|
||||
drawntext = drawntext.Left(drawntext.Length() - 1);
|
||||
}
|
||||
|
||||
// if still not enough space, remove ellipsis characters
|
||||
while (ellipsis.Length() > 0 && w + base_w > width) {
|
||||
ellipsis = ellipsis.Left(ellipsis.Length() - 1);
|
||||
dc->GetTextExtent(ellipsis, &base_w, &h);
|
||||
}
|
||||
|
||||
// now draw the text
|
||||
dc->DrawText(drawntext, x, y);
|
||||
dc->DrawText(ellipsis, x + w, y);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool wxListLineData::Highlight( bool on )
|
||||
{
|
||||
wxCHECK_MSG( !m_owner->IsVirtual(), FALSE, _T("unexpected call to Highlight") );
|
||||
|
Reference in New Issue
Block a user