+ m_currentEdit = item.m_pItem;
+
+ wxTreeEvent te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, GetId() );
+ te.m_item = m_currentEdit;
+ te.SetEventObject( this );
+ GetEventHandler()->ProcessEvent( te );
+
+ if (!te.IsAllowed()) return;
+
+ // We have to call this here because the label in
+ // question might just have been added and no screen
+ // update taken place.
+ if (m_dirty) wxYield();
+
+ wxString s = m_currentEdit->GetText();
+ int x = m_currentEdit->GetX();
+ int y = m_currentEdit->GetY();
+ int w = m_currentEdit->GetWidth();
+ int h = m_currentEdit->GetHeight();
+
+ int image_h = 0;
+ int image_w = 0;
+ if ((m_currentEdit->IsExpanded()) && (m_currentEdit->GetSelectedImage() != -1))
+ {
+ m_imageListNormal->GetSize( m_currentEdit->GetSelectedImage(), image_w, image_h );
+ image_w += 4;
+ }
+ else if (m_currentEdit->GetImage() != -1)
+ {
+ m_imageListNormal->GetSize( m_currentEdit->GetImage(), image_w, image_h );
+ image_w += 4;
+ }
+ x += image_w;
+ w -= image_w + 4; // I don't know why +4 is needed
+
+ wxClientDC dc(this);
+ PrepareDC( dc );
+ x = dc.LogicalToDeviceX( x );
+ y = dc.LogicalToDeviceY( y );
+
+ wxTreeTextCtrl *text = new wxTreeTextCtrl(
+ this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) );
+ text->SetFocus();
+}
+
+void wxTreeCtrl::OnRenameTimer()
+{
+ Edit( m_current );
+}
+
+void wxTreeCtrl::OnRenameAccept()
+{
+ wxTreeEvent le( wxEVT_COMMAND_TREE_END_LABEL_EDIT, GetId() );
+ le.m_item = m_currentEdit;
+ le.SetEventObject( this );
+ le.m_label = m_renameRes;
+ GetEventHandler()->ProcessEvent( le );
+
+ if (!le.IsAllowed()) return;
+
+ SetItemText( m_currentEdit, m_renameRes );
+}
+
+void wxTreeCtrl::OnMouse( wxMouseEvent &event )
+{
+ if ( !(event.LeftUp() || event.LeftDClick() || event.Dragging()) ) return;
+
+ 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(_T("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;
+ 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);