+ int flags=0;
+ wxGenericTreeItem *item = m_anchor->HitTest( wxPoint(x,y), this, flags);
+ bool onButton = flags & wxTREE_HITTEST_ONITEMBUTTON;
+
+ if (item == NULL) return; /* we hit the blank area */
+
+ if (event.Dragging())
+ {
+ if (m_dragCount == 2) /* small drag latency (3?) */
+ {
+ m_dragCount = 0;
+
+ wxTreeEvent nevent(wxEVT_COMMAND_TREE_BEGIN_DRAG, GetId());
+ nevent.m_item = m_current;
+ nevent.SetEventObject(this);
+ GetEventHandler()->ProcessEvent(nevent);
+ }
+ else
+ {
+ m_dragCount++;
+ }
+ return;
+ }
+
+ if (event.LeftUp() && (item == m_current) &&
+ (flags & wxTREE_HITTEST_ONITEMLABEL) &&
+ HasFlag(wxTR_EDIT_LABELS) )
+ {
+ m_renameTimer->Start( 100, TRUE );
+ return;
+ }
+
+ bool is_multiple=(GetWindowStyleFlag() & wxTR_MULTIPLE);
+ bool extended_select=(event.ShiftDown() && is_multiple);
+ bool unselect_others=!(extended_select || (event.ControlDown() && is_multiple));
+
+ if (onButton)
+ {
+ Toggle( item );
+ if (is_multiple)
+ return;
+ }
+
+ SelectItem(item, unselect_others, extended_select);
+
+ if (event.LeftDClick())
+ {
+ wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
+ event.m_item = item;
+ event.m_code = 0;
+ event.SetEventObject( this );
+ GetEventHandler()->ProcessEvent( event );
+ }
+}
+
+void wxTreeCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
+{
+ /* after all changes have been done to the tree control,
+ * we actually redraw the tree when everything is over */
+
+ if (!m_dirty)
+ return;
+
+ m_dirty = FALSE;
+
+ CalculatePositions();
+ Refresh();
+ AdjustMyScrollbars();
+}
+
+void wxTreeCtrl::CalculateSize( wxGenericTreeItem *item, wxDC &dc )
+{
+ long text_w = 0;
+ long text_h = 0;
+ // TODO : check for boldness. Here with suppose that font normal and bold
+ // have the same height !
+ // TODO : bug here, text_w is sometime not the correct answer !!!
+ dc.GetTextExtent( item->GetText(), &text_w, &text_h );
+ text_h+=4;
+
+ int image_h = 0;
+ int image_w = 0;
+ if ((item->IsExpanded()) && (item->GetSelectedImage() != -1))
+ {
+ m_imageListNormal->GetSize( item->GetSelectedImage(), image_w, image_h );
+ image_w += 4;
+ }
+ else if (item->GetImage() != -1)
+ {
+ m_imageListNormal->GetSize( item->GetImage(), image_w, image_h );
+ image_w += 4;
+ }
+
+ int total_h = (image_h > text_h) ? image_h : text_h;
+
+ if (total_h<40) total_h+=4; // at least 4 pixels
+ else total_h+=total_h/10; // otherwise 10% extra spacing
+
+ item->SetHeight(total_h);
+ if (total_h>m_lineHeight) m_lineHeight=total_h;
+
+ item->SetWidth(image_w+text_w+2);
+}
+
+// -----------------------------------------------------------------------------
+// for developper : y is now the top of the level
+// not the middle of it !
+void wxTreeCtrl::CalculateLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y )
+{
+ int horizX = level*m_indent;
+
+ CalculateSize( item, dc );
+
+ // set its position
+ item->SetX( horizX+m_indent+m_spacing );
+ item->SetY( y );
+ y+=GetLineHeight(item);
+
+ if ( !item->IsExpanded() )
+ {
+ // we dont need to calculate collapsed branches
+ return;
+ }
+
+ wxArrayGenericTreeItems& children = item->GetChildren();
+ size_t n, count = children.Count();
+ for (n = 0; n < count; ++n )
+ CalculateLevel( children[n], dc, level+1, y ); // recurse