+wxListItemData::wxListItemData(wxListMainWindow *owner)
+{
+ Init();
+
+ m_owner = owner;
+
+ if ( owner->InReportView() )
+ m_rect = NULL;
+ else
+ m_rect = new wxRect;
+}
+
+void wxListItemData::SetItem( const wxListItem &info )
+{
+ if ( info.m_mask & wxLIST_MASK_TEXT )
+ SetText(info.m_text);
+ if ( info.m_mask & wxLIST_MASK_IMAGE )
+ m_image = info.m_image;
+ if ( info.m_mask & wxLIST_MASK_DATA )
+ m_data = info.m_data;
+
+ if ( info.HasAttributes() )
+ {
+ if ( m_attr )
+ *m_attr = *info.GetAttributes();
+ else
+ m_attr = new wxListItemAttr(*info.GetAttributes());
+ }
+
+ if ( m_rect )
+ {
+ m_rect->x =
+ m_rect->y =
+ m_rect->height = 0;
+ m_rect->width = info.m_width;
+ }
+}
+
+void wxListItemData::SetPosition( int x, int y )
+{
+ wxCHECK_RET( m_rect, _T("unexpected SetPosition() call") );
+
+ m_rect->x = x;
+ m_rect->y = y;
+}
+
+void wxListItemData::SetSize( int width, int height )
+{
+ wxCHECK_RET( m_rect, _T("unexpected SetSize() call") );
+
+ if ( width != -1 )
+ m_rect->width = width;
+ if ( height != -1 )
+ m_rect->height = height;
+}
+
+bool wxListItemData::IsHit( int x, int y ) const
+{
+ wxCHECK_MSG( m_rect, false, _T("can't be called in this mode") );
+
+ return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x, y);
+}
+
+int wxListItemData::GetX() const
+{
+ wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
+
+ return m_rect->x;
+}
+
+int wxListItemData::GetY() const
+{
+ wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
+
+ return m_rect->y;
+}
+
+int wxListItemData::GetWidth() const
+{
+ wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
+
+ return m_rect->width;
+}
+
+int wxListItemData::GetHeight() const
+{
+ wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
+
+ return m_rect->height;
+}
+
+void wxListItemData::GetItem( wxListItem &info ) const
+{
+ long mask = info.m_mask;
+ if ( !mask )
+ // by default, get everything for backwards compatibility
+ mask = -1;
+
+ if ( mask & wxLIST_MASK_TEXT )
+ info.m_text = m_text;
+ if ( mask & wxLIST_MASK_IMAGE )
+ info.m_image = m_image;
+ if ( mask & wxLIST_MASK_DATA )
+ info.m_data = m_data;
+
+ if ( m_attr )
+ {
+ if ( m_attr->HasTextColour() )
+ info.SetTextColour(m_attr->GetTextColour());
+ if ( m_attr->HasBackgroundColour() )
+ info.SetBackgroundColour(m_attr->GetBackgroundColour());
+ if ( m_attr->HasFont() )
+ info.SetFont(m_attr->GetFont());
+ }
+}
+
+//-----------------------------------------------------------------------------
+// wxListHeaderData
+//-----------------------------------------------------------------------------
+
+void wxListHeaderData::Init()
+{
+ m_mask = 0;
+ m_image = -1;
+ m_format = 0;
+ m_width = 0;
+ m_xpos = 0;
+ m_ypos = 0;
+ m_height = 0;
+}
+
+wxListHeaderData::wxListHeaderData()
+{
+ Init();
+}
+
+wxListHeaderData::wxListHeaderData( const wxListItem &item )
+{
+ Init();
+
+ SetItem( item );
+}
+
+void wxListHeaderData::SetItem( const wxListItem &item )
+{
+ m_mask = item.m_mask;
+
+ if ( m_mask & wxLIST_MASK_TEXT )
+ m_text = item.m_text;
+
+ if ( m_mask & wxLIST_MASK_IMAGE )
+ m_image = item.m_image;
+
+ if ( m_mask & wxLIST_MASK_FORMAT )
+ m_format = item.m_format;
+
+ if ( m_mask & wxLIST_MASK_WIDTH )
+ SetWidth(item.m_width);
+}
+
+void wxListHeaderData::SetPosition( int x, int y )
+{
+ m_xpos = x;
+ m_ypos = y;
+}
+
+void wxListHeaderData::SetHeight( int h )
+{
+ m_height = h;
+}
+
+void wxListHeaderData::SetWidth( int w )
+{
+ m_width = w < 0 ? WIDTH_COL_DEFAULT : w;
+}
+
+void wxListHeaderData::SetFormat( int format )
+{
+ m_format = format;
+}
+
+bool wxListHeaderData::HasImage() const
+{
+ return m_image != -1;
+}
+
+bool wxListHeaderData::IsHit( int x, int y ) const
+{
+ return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
+}
+
+void wxListHeaderData::GetItem( wxListItem& item )
+{
+ item.m_mask = m_mask;
+ item.m_text = m_text;
+ item.m_image = m_image;
+ item.m_format = m_format;
+ item.m_width = m_width;
+}
+
+int wxListHeaderData::GetImage() const
+{
+ return m_image;
+}
+
+int wxListHeaderData::GetWidth() const
+{
+ return m_width;
+}
+
+int wxListHeaderData::GetFormat() const
+{
+ return m_format;
+}
+
+//-----------------------------------------------------------------------------
+// wxListLineData
+//-----------------------------------------------------------------------------
+
+inline int wxListLineData::GetMode() const
+{
+ return m_owner->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE;
+}
+
+inline bool wxListLineData::InReportView() const
+{
+ return m_owner->HasFlag(wxLC_REPORT);
+}
+
+inline bool wxListLineData::IsVirtual() const
+{
+ return m_owner->IsVirtual();
+}
+
+wxListLineData::wxListLineData( wxListMainWindow *owner )
+{
+ m_owner = owner;
+
+ if ( InReportView() )
+ m_gi = NULL;
+ else // !report
+ m_gi = new GeometryInfo;
+
+ m_highlighted = false;
+
+ InitItems( GetMode() == wxLC_REPORT ? m_owner->GetColumnCount() : 1 );
+}
+
+void wxListLineData::CalculateSize( wxDC *dc, int spacing )
+{
+ wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
+ wxCHECK_RET( node, _T("no subitems at all??") );
+
+ wxListItemData *item = node->GetData();
+
+ wxString s;
+ wxCoord lw, lh;
+
+ switch ( GetMode() )
+ {
+ case wxLC_ICON:
+ case wxLC_SMALL_ICON:
+ m_gi->m_rectAll.width = spacing;
+
+ s = item->GetText();
+
+ if ( s.empty() )
+ {
+ lh =
+ m_gi->m_rectLabel.width =
+ m_gi->m_rectLabel.height = 0;
+ }
+ else // has label
+ {
+ dc->GetTextExtent( s, &lw, &lh );
+ lw += EXTRA_WIDTH;
+ lh += EXTRA_HEIGHT;
+
+ m_gi->m_rectAll.height = spacing + lh;
+ if (lw > spacing)
+ m_gi->m_rectAll.width = lw;
+
+ m_gi->m_rectLabel.width = lw;
+ m_gi->m_rectLabel.height = lh;
+ }
+
+ if (item->HasImage())
+ {
+ int w, h;
+ m_owner->GetImageSize( item->GetImage(), w, h );
+ m_gi->m_rectIcon.width = w + 8;
+ m_gi->m_rectIcon.height = h + 8;
+
+ if ( m_gi->m_rectIcon.width > m_gi->m_rectAll.width )
+ m_gi->m_rectAll.width = m_gi->m_rectIcon.width;
+ if ( m_gi->m_rectIcon.height + lh > m_gi->m_rectAll.height - 4 )
+ m_gi->m_rectAll.height = m_gi->m_rectIcon.height + lh + 4;
+ }
+
+ if ( item->HasText() )
+ {
+ m_gi->m_rectHighlight.width = m_gi->m_rectLabel.width;
+ m_gi->m_rectHighlight.height = m_gi->m_rectLabel.height;
+ }
+ else // no text, highlight the icon
+ {
+ m_gi->m_rectHighlight.width = m_gi->m_rectIcon.width;
+ m_gi->m_rectHighlight.height = m_gi->m_rectIcon.height;
+ }
+ break;
+
+ case wxLC_LIST:
+ s = item->GetTextForMeasuring();
+
+ dc->GetTextExtent( s, &lw, &lh );
+ lw += EXTRA_WIDTH;
+ lh += EXTRA_HEIGHT;
+
+ m_gi->m_rectLabel.width = lw;
+ m_gi->m_rectLabel.height = lh;
+
+ m_gi->m_rectAll.width = lw;
+ m_gi->m_rectAll.height = lh;
+
+ if (item->HasImage())
+ {
+ int w, h;
+ m_owner->GetImageSize( item->GetImage(), w, h );
+ m_gi->m_rectIcon.width = w;
+ m_gi->m_rectIcon.height = h;
+
+ m_gi->m_rectAll.width += 4 + w;
+ if (h > m_gi->m_rectAll.height)
+ m_gi->m_rectAll.height = h;
+ }
+
+ m_gi->m_rectHighlight.width = m_gi->m_rectAll.width;
+ m_gi->m_rectHighlight.height = m_gi->m_rectAll.height;
+ break;
+
+ case wxLC_REPORT:
+ wxFAIL_MSG( _T("unexpected call to SetSize") );
+ break;
+
+ default:
+ wxFAIL_MSG( _T("unknown mode") );
+ break;
+ }
+}
+
+void wxListLineData::SetPosition( int x, int y, int spacing )
+{
+ wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
+ wxCHECK_RET( node, _T("no subitems at all??") );
+
+ wxListItemData *item = node->GetData();
+
+ switch ( GetMode() )
+ {
+ case wxLC_ICON:
+ case wxLC_SMALL_ICON:
+ m_gi->m_rectAll.x = x;
+ m_gi->m_rectAll.y = y;
+
+ if ( item->HasImage() )
+ {
+ m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4 +
+ (m_gi->m_rectAll.width - m_gi->m_rectIcon.width) / 2;
+ m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4;
+ }
+
+ if ( item->HasText() )
+ {
+ if (m_gi->m_rectAll.width > spacing)
+ m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2;
+ else
+ m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2 + (spacing / 2) - (m_gi->m_rectLabel.width / 2);
+ m_gi->m_rectLabel.y = m_gi->m_rectAll.y + m_gi->m_rectAll.height + 2 - m_gi->m_rectLabel.height;
+ m_gi->m_rectHighlight.x = m_gi->m_rectLabel.x - 2;
+ m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - 2;
+ }
+ else // no text, highlight the icon
+ {
+ m_gi->m_rectHighlight.x = m_gi->m_rectIcon.x - 4;
+ m_gi->m_rectHighlight.y = m_gi->m_rectIcon.y - 4;
+ }
+ break;
+
+ case wxLC_LIST:
+ m_gi->m_rectAll.x = x;
+ m_gi->m_rectAll.y = y;
+
+ m_gi->m_rectHighlight.x = m_gi->m_rectAll.x;
+ m_gi->m_rectHighlight.y = m_gi->m_rectAll.y;
+ m_gi->m_rectLabel.y = m_gi->m_rectAll.y + 2;
+
+ if (item->HasImage())
+ {
+ m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 2;
+ m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 2;
+ m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 6 + m_gi->m_rectIcon.width;
+ }
+ else
+ {
+ m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2;
+ }
+ break;
+
+ case wxLC_REPORT:
+ wxFAIL_MSG( _T("unexpected call to SetPosition") );
+ break;
+
+ default:
+ wxFAIL_MSG( _T("unknown mode") );
+ break;
+ }
+}
+
+void wxListLineData::InitItems( int num )
+{
+ for (int i = 0; i < num; i++)
+ m_items.Append( new wxListItemData(m_owner) );
+}
+
+void wxListLineData::SetItem( int index, const wxListItem &info )
+{
+ wxListItemDataList::compatibility_iterator node = m_items.Item( index );
+ wxCHECK_RET( node, _T("invalid column index in SetItem") );
+
+ wxListItemData *item = node->GetData();
+ item->SetItem( info );
+}
+
+void wxListLineData::GetItem( int index, wxListItem &info )
+{
+ wxListItemDataList::compatibility_iterator node = m_items.Item( index );
+ if (node)
+ {
+ wxListItemData *item = node->GetData();
+ item->GetItem( info );
+ }
+}
+
+wxString wxListLineData::GetText(int index) const
+{
+ wxString s;
+
+ wxListItemDataList::compatibility_iterator node = m_items.Item( index );
+ if (node)
+ {
+ wxListItemData *item = node->GetData();
+ s = item->GetText();
+ }
+
+ return s;
+}
+
+void wxListLineData::SetText( int index, const wxString& s )
+{
+ wxListItemDataList::compatibility_iterator node = m_items.Item( index );
+ if (node)
+ {
+ wxListItemData *item = node->GetData();
+ item->SetText( s );
+ }
+}
+
+void wxListLineData::SetImage( int index, int image )
+{
+ wxListItemDataList::compatibility_iterator node = m_items.Item( index );
+ wxCHECK_RET( node, _T("invalid column index in SetImage()") );
+
+ wxListItemData *item = node->GetData();
+ item->SetImage(image);
+}
+
+int wxListLineData::GetImage( int index ) const
+{
+ wxListItemDataList::compatibility_iterator node = m_items.Item( index );
+ wxCHECK_MSG( node, -1, _T("invalid column index in GetImage()") );
+
+ wxListItemData *item = node->GetData();
+ return item->GetImage();
+}
+
+wxListItemAttr *wxListLineData::GetAttr() const
+{
+ wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
+ wxCHECK_MSG( node, NULL, _T("invalid column index in GetAttr()") );
+
+ wxListItemData *item = node->GetData();
+ return item->GetAttr();
+}
+
+void wxListLineData::SetAttr(wxListItemAttr *attr)
+{
+ wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
+ wxCHECK_RET( node, _T("invalid column index in SetAttr()") );
+
+ wxListItemData *item = node->GetData();
+ item->SetAttr(attr);
+}
+
+bool wxListLineData::SetAttributes(wxDC *dc,
+ const wxListItemAttr *attr,
+ bool highlighted)
+{
+ wxWindow *listctrl = m_owner->GetParent();
+
+ // fg colour
+
+ // don't use foreground colour for drawing highlighted items - this might
+ // make them completely invisible (and there is no way to do bit
+ // arithmetics on wxColour, unfortunately)
+ wxColour colText;
+ if ( highlighted )
+ colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
+ else if ( attr && attr->HasTextColour() )
+ colText = attr->GetTextColour();
+ else
+ colText = listctrl->GetForegroundColour();
+
+ dc->SetTextForeground(colText);
+
+ // font
+ wxFont font;
+ if ( attr && attr->HasFont() )
+ font = attr->GetFont();
+ else
+ font = listctrl->GetFont();
+
+ dc->SetFont(font);
+
+ // bg colour
+ bool hasBgCol = attr && attr->HasBackgroundColour();
+ if ( highlighted || hasBgCol )
+ {
+ if ( highlighted )
+ dc->SetBrush( *m_owner->GetHighlightBrush() );
+ else
+ dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID));
+
+ dc->SetPen( *wxTRANSPARENT_PEN );
+
+ return true;
+ }
+
+ return false;
+}
+
+void wxListLineData::Draw( wxDC *dc )
+{
+ wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
+ wxCHECK_RET( node, _T("no subitems at all??") );
+
+ bool highlighted = IsHighlighted();
+
+ wxListItemAttr *attr = GetAttr();
+
+ if ( SetAttributes(dc, attr, highlighted) )
+ dc->DrawRectangle( m_gi->m_rectHighlight );
+
+ // just for debugging to better see where the items are
+#if 0
+ dc->SetPen(*wxRED_PEN);
+ dc->SetBrush(*wxTRANSPARENT_BRUSH);
+ dc->DrawRectangle( m_gi->m_rectAll );
+ dc->SetPen(*wxGREEN_PEN);
+ dc->DrawRectangle( m_gi->m_rectIcon );
+#endif
+
+ wxListItemData *item = node->GetData();
+ if (item->HasImage())
+ {
+ // centre the image inside our rectangle, this looks nicer when items
+ // ae aligned in a row
+ const wxRect& rectIcon = m_gi->m_rectIcon;
+
+ m_owner->DrawImage(item->GetImage(), dc, rectIcon.x, rectIcon.y);
+ }
+
+ if (item->HasText())
+ {
+ const wxRect& rectLabel = m_gi->m_rectLabel;
+
+ wxDCClipper clipper(*dc, rectLabel);
+ dc->DrawText(item->GetText(), rectLabel.x, rectLabel.y);
+ }
+}
+
+void wxListLineData::DrawInReportMode( wxDC *dc,
+ const wxRect& rect,
+ const wxRect& rectHL,
+ bool highlighted )
+{
+ // TODO: later we should support setting different attributes for
+ // different columns - to do it, just add "col" argument to
+ // GetAttr() and move these lines into the loop below
+ wxListItemAttr *attr = GetAttr();
+ if ( SetAttributes(dc, attr, highlighted) )
+ dc->DrawRectangle( rectHL );
+
+ wxCoord x = rect.x + HEADER_OFFSET_X,
+ yMid = rect.y + rect.height/2;
+
+ size_t col = 0;
+ for ( wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
+ node;
+ node = node->GetNext(), col++ )
+ {
+ wxListItemData *item = node->GetData();
+
+ int width = m_owner->GetColumnWidth(col);
+ int xOld = x;
+ x += width;
+
+ if ( item->HasImage() )
+ {
+ int ix, iy;
+ m_owner->GetImageSize( item->GetImage(), ix, iy );
+ m_owner->DrawImage( item->GetImage(), dc, xOld, yMid - iy/2 );
+
+ ix += IMAGE_MARGIN_IN_REPORT_MODE;
+
+ xOld += ix;
+ width -= ix;
+ }
+
+ if ( item->HasText() )
+ DrawTextFormatted(dc, item->GetText(), col, xOld, yMid, width - 8);
+ }
+}
+
+void wxListLineData::DrawTextFormatted(wxDC *dc,
+ const wxString &text,
+ int col,
+ int x,
+ int yMid,
+ int width)