diff --git a/include/wx/generic/private/listctrl.h b/include/wx/generic/private/listctrl.h index ff6672fc99..c5741b6b13 100644 --- a/include/wx/generic/private/listctrl.h +++ b/include/wx/generic/private/listctrl.h @@ -649,7 +649,8 @@ public: { return GetSubItemRect(item, wxLIST_GETSUBITEMRECT_WHOLEITEM, rect); } - bool GetSubItemRect( long item, long subItem, wxRect& rect ) const; + bool GetSubItemRect( long item, long subItem, wxRect& rect, + int code = wxLIST_RECT_BOUNDS ) const; wxRect GetViewRect() const; bool GetItemPosition( long item, wxPoint& pos ) const; int GetSelectedItemCount() const; diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 5b7c511bd2..7e7e679158 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -809,6 +809,8 @@ void wxListLineData::DrawInReportMode( wxDC *dc, // different columns - to do it, just add "col" argument to // GetAttr() and move these lines into the loop below + // Note: GetSubItemRect() needs to be modified if the layout here changes. + ApplyAttributes(dc, rectHL, highlighted, current); wxCoord x = rect.x + HEADER_OFFSET_X + ICON_OFFSET_X, @@ -3678,7 +3680,8 @@ wxRect wxListMainWindow::GetViewRect() const } bool -wxListMainWindow::GetSubItemRect(long item, long subItem, wxRect& rect) const +wxListMainWindow::GetSubItemRect(long item, long subItem, wxRect& rect, + int code) const { wxCHECK_MSG( subItem == wxLIST_GETSUBITEMRECT_WHOLEITEM || InReportView(), false, @@ -3706,6 +3709,51 @@ wxListMainWindow::GetSubItemRect(long item, long subItem, wxRect& rect) const rect.x += GetColumnWidth(i); } rect.width = GetColumnWidth(subItem); + + switch ( code ) + { + case wxLIST_RECT_BOUNDS: + // Nothing to do. + break; + + case wxLIST_RECT_ICON: + case wxLIST_RECT_LABEL: + // Note: this needs to be kept in sync with DrawInReportMode(). + { + rect.x += ICON_OFFSET_X; + rect.width -= ICON_OFFSET_X; + + wxListLineData* const line = GetLine(item); + if ( subItem == 0 && line->HasImage() ) + { + int ix, iy; + GetImageSize(line->GetImage(), ix, iy); + + const int iconWidth = ix + IMAGE_MARGIN_IN_REPORT_MODE; + + if ( code == wxLIST_RECT_ICON ) + { + rect.width = iconWidth; + } + else // wxLIST_RECT_LABEL + { + rect.x += iconWidth; + rect.width -= iconWidth; + } + } + else // No icon + { + if ( code == wxLIST_RECT_ICON ) + rect = wxRect(); + //else: label rect is the same as the full one + } + } + break; + + default: + wxFAIL_MSG(wxS("Unknown rectangle requested")); + return false; + } } GetListCtrl()->CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y); @@ -5033,9 +5081,9 @@ bool wxGenericListCtrl::GetItemRect(long item, wxRect& rect, int code) const bool wxGenericListCtrl::GetSubItemRect(long item, long subItem, wxRect& rect, - int WXUNUSED(code)) const + int code) const { - if ( !m_mainWin->GetSubItemRect( item, subItem, rect ) ) + if ( !m_mainWin->GetSubItemRect( item, subItem, rect, code ) ) return false; if ( m_mainWin->HasHeader() )