+ bool hasBgCol = attr && attr->HasBackgroundColour();
+ dc.SetBackgroundMode(hasBgCol ? wxSOLID : wxTRANSPARENT);
+ if ( hasBgCol )
+ dc.SetTextBackground(attr->GetBackgroundColour());
+ dc.DrawText( item->GetText(), image_w + item->GetX(), item->GetY()
+ + ((total_h > text_h) ? (total_h - text_h)/2 : 0));
+
+ // restore normal font
+ dc.SetFont( m_normalFont );
+}
+
+// Now y stands for the top of the item, whereas it used to stand for middle !
+void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y )
+{
+ int horizX = level*m_indent;
+
+ item->SetX( horizX+m_indent+m_spacing );
+ item->SetY( y );
+
+ int oldY = y;
+ y+=GetLineHeight(item)/2;
+
+ item->SetCross( horizX+m_indent, y );
+
+ int exposed_x = dc.LogicalToDeviceX( 0 );
+ int exposed_y = dc.LogicalToDeviceY( item->GetY() );
+
+ if (IsExposed( exposed_x, exposed_y, 10000, GetLineHeight(item) )) // 10000 = very much
+ {
+ int startX = horizX;
+ int endX = horizX + (m_indent-5);
+
+// if (!item->HasChildren()) endX += (m_indent+5);
+ if (!item->HasChildren()) endX += 20;
+
+ dc.DrawLine( startX, y, endX, y );
+
+ if (item->HasPlus())
+ {
+ dc.DrawLine( horizX+(m_indent+5), y, horizX+(m_indent+15), y );
+ dc.SetPen( *wxGREY_PEN );
+ dc.SetBrush( *wxWHITE_BRUSH );
+ dc.DrawRectangle( horizX+(m_indent-5), y-4, 11, 9 );
+
+ dc.SetPen( *wxBLACK_PEN );
+ dc.DrawLine( horizX+(m_indent-2), y, horizX+(m_indent+3), y );
+ if (!item->IsExpanded())
+ dc.DrawLine( horizX+m_indent, y-2, horizX+m_indent, y+3 );
+
+ dc.SetPen( m_dottedPen );
+ }
+
+ wxPen *pen = wxTRANSPARENT_PEN;
+ wxBrush *brush; // FIXME is this really needed?
+ wxColour colText;
+
+ if ( item->IsSelected() )
+ {
+ colText = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
+
+ brush = m_hilightBrush;
+
+ if ( m_hasFocus )
+ pen = wxBLACK_PEN;
+
+ }
+ else
+ {
+ wxTreeItemAttr *attr = item->GetAttributes();
+ if ( attr && attr->HasTextColour() )
+ colText = attr->GetTextColour();
+ else
+ colText = *wxBLACK;
+
+ brush = wxWHITE_BRUSH;
+ }
+
+ // prepare to draw
+ dc.SetTextForeground(colText);
+ dc.SetPen(*pen);
+ dc.SetBrush(*brush);
+
+ // draw
+ PaintItem(item, dc);
+
+ // restore DC objects
+ dc.SetBrush( *wxWHITE_BRUSH );
+ dc.SetPen( m_dottedPen );
+ dc.SetTextForeground( *wxBLACK );
+ }
+
+ y = oldY+GetLineHeight(item);
+
+ if (item->IsExpanded())
+ {
+ oldY+=GetLineHeight(item)/2;
+ int semiOldY=0;
+
+ wxArrayGenericTreeItems& children = item->GetChildren();
+ size_t n, count = children.Count();
+ for ( n = 0; n < count; ++n )
+ {
+ semiOldY=y;
+ PaintLevel( children[n], dc, level+1, y );
+ }
+
+ // it may happen that the item is expanded but has no items (when you
+ // delete all its children for example) - don't draw the vertical line
+ // in this case
+ if (count > 0)
+ {
+ semiOldY+=GetLineHeight(children[--n])/2;
+ dc.DrawLine( horizX+m_indent, oldY+5, horizX+m_indent, semiOldY );
+ }
+ }
+}
+
+void wxTreeCtrl::DrawBorder(wxTreeItemId &item)
+{
+ if (!item) return;
+
+ wxGenericTreeItem *i=item.m_pItem;
+
+ wxClientDC dc(this);
+ PrepareDC( dc );
+ dc.SetLogicalFunction(wxINVERT);
+
+ int w,h,x;
+ ViewStart(&x,&h); // we only need x
+ GetClientSize(&w,&h); // we only need w
+
+ h=GetLineHeight(i)+1;
+ // 2 white column at border
+ dc.DrawRectangle( PIXELS_PER_UNIT*x+2, i->GetY()-1, w-6, h);
+}
+
+void wxTreeCtrl::DrawLine(wxTreeItemId &item, bool below)
+{
+ if (!item) return;
+
+ wxGenericTreeItem *i=item.m_pItem;
+
+ wxClientDC dc(this);
+ PrepareDC( dc );
+ dc.SetLogicalFunction(wxINVERT);
+
+ int w,h,y;
+ GetSize(&w,&h);
+
+ if (below) y=i->GetY()+GetLineHeight(i)-1;
+ else y=i->GetY();
+
+ dc.DrawLine( 0, y, w, y);