+ 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);
+ }
+ else // otherwise, truncate and add an ellipsis if possible
+ {
+ // 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);