+ if ( !m_anchor ) return;
+
+ wxClientDC dc(this);
+ PrepareDC(dc);
+ long x = dc.DeviceToLogicalX( (long)event.GetX() );
+ long y = dc.DeviceToLogicalY( (long)event.GetY() );
+
+ int flags=0;
+ wxGenericTreeItem *item = m_anchor->HitTest( wxPoint(x,y), this, flags);
+ bool onButton = flags & wxTREE_HITTEST_ONITEMBUTTON;
+
+ if (event.Dragging())
+ {
+ if (m_dragCount == 0)
+ m_dragStart = wxPoint(x,y);
+
+ m_dragCount++;
+
+ if (m_dragCount != 3) return;
+
+ int command = wxEVT_COMMAND_TREE_BEGIN_DRAG;
+ if (event.RightIsDown()) command = wxEVT_COMMAND_TREE_BEGIN_RDRAG;
+
+ wxTreeEvent nevent( command, GetId() );
+ nevent.m_item = m_current;
+ nevent.SetEventObject(this);
+ GetEventHandler()->ProcessEvent(nevent);
+ return;
+ }
+ else
+ {
+ m_dragCount = 0;
+ }
+
+ if (item == NULL) return; /* we hit the blank area */
+
+ 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;
+
+ wxFont fontOld;
+ wxFont fontNew;
+ if (item->IsBold())
+ {
+ fontOld = dc.GetFont();
+ if (fontOld.Ok())
+ {
+ // VZ: is there any better way to make a bold variant of old font?
+ fontNew = wxFont( fontOld.GetPointSize(),
+ fontOld.GetFamily(),
+ fontOld.GetStyle(),
+ wxBOLD,
+ fontOld.GetUnderlined());
+ dc.SetFont(fontNew);
+ }
+ else
+ {
+ wxFAIL_MSG(wxT("wxDC::GetFont() failed!"));
+ }
+ }
+
+ dc.GetTextExtent( item->GetText(), &text_w, &text_h );
+ text_h+=2;
+
+ // restore normal font for bold items
+ if (fontOld.Ok())
+ dc.SetFont( fontOld);
+
+ int image_h = 0;
+ int image_w = 0;
+ int image = item->GetCurrentImage();
+ if ( image != NO_IMAGE )
+ {
+ m_imageListNormal->GetSize( image, 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