]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/treectlg.cpp
Don't scroll the grid when starting a cell editor if it will already
[wxWidgets.git] / src / generic / treectlg.cpp
index 2ce619061bc0cbcffb9cc94dfc35627393680bad..577ecbc4e1615e58d728763662f142675ac6ec01 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        treectlg.cpp
+// Name:        src/generic/treectlg.cpp
 // Purpose:     generic tree control implementation
 // Author:      Robert Roebling
 // Created:     01/02/97
 
 #if wxUSE_TREECTRL
 
-#include "wx/treebase.h"
+#include "wx/treectrl.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/dcclient.h"
+#endif
+
 #include "wx/generic/treectlg.h"
 #include "wx/timer.h"
 #include "wx/textctrl.h"
 #include "wx/imaglist.h"
 #include "wx/settings.h"
-#include "wx/dcclient.h"
 
 #include "wx/renderer.h"
 
@@ -56,6 +60,9 @@ static const int NO_IMAGE = -1;
 
 static const int PIXELS_PER_UNIT = 10;
 
+// the margin between the item image and the item text
+static const int MARGIN_BETWEEN_IMAGE_AND_TEXT = 4;
+
 // -----------------------------------------------------------------------------
 // private classes
 // -----------------------------------------------------------------------------
@@ -84,6 +91,24 @@ class WXDLLEXPORT wxTreeTextCtrl: public wxTextCtrl
 public:
     wxTreeTextCtrl(wxGenericTreeCtrl *owner, wxGenericTreeItem *item);
 
+    void EndEdit(bool discardChanges = false)
+    {
+        if ( discardChanges )
+        {
+            StopEditing();
+        }
+        else
+        {
+            m_aboutToFinish = true;
+
+            // Notify the owner about the changes
+            AcceptChanges();
+
+            // Even if vetoed, close the control (consistent with MSW)
+            Finish();
+        }
+    }
+
     void StopEditing()
     {
         Finish();
@@ -177,9 +202,9 @@ public:
     wxGenericTreeItem *GetParent() const { return m_parent; }
 
     // operations
-        // deletes all children notifying the treectrl about it if !NULL
-        // pointer given
-    void DeleteChildren(wxGenericTreeCtrl *tree = NULL);
+
+    // deletes all children notifying the treectrl about it
+    void DeleteChildren(wxGenericTreeCtrl *tree);
 
     // get count of all children (and grand children if 'recursively')
     size_t GetChildrenCount(bool recursively = true) const;
@@ -355,7 +380,7 @@ wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl *owner,
         if ( m_owner->m_imageListNormal )
         {
             m_owner->m_imageListNormal->GetSize( image, image_w, image_h );
-            image_w += 4;
+            image_w += MARGIN_BETWEEN_IMAGE_AND_TEXT;
         }
         else
         {
@@ -419,7 +444,7 @@ void wxTreeTextCtrl::Finish()
 
         m_finished = true;
 
-        m_owner->SetFocusIgnoringChildren();
+        m_owner->SetFocus();
     }
 }
 
@@ -428,11 +453,7 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
     switch ( event.m_keyCode )
     {
         case WXK_RETURN:
-            m_aboutToFinish = true;
-            // Notify the owner about the changes
-            AcceptChanges();
-            // Even if vetoed, close the control (consistent with MSW)
-            Finish();
+            EndEdit();
             break;
 
         case WXK_ESCAPE:
@@ -530,11 +551,10 @@ void wxGenericTreeItem::DeleteChildren(wxGenericTreeCtrl *tree)
     for ( size_t n = 0; n < count; n++ )
     {
         wxGenericTreeItem *child = m_children[n];
-        if (tree)
-            tree->SendDeleteEvent(child);
+        tree->SendDeleteEvent(child);
 
         child->DeleteChildren(tree);
-        if (child == tree->m_select_me)
+        if ( child == tree->m_select_me )
             tree->m_select_me = NULL;
         delete child;
     }
@@ -695,9 +715,9 @@ int wxGenericTreeItem::GetCurrentImage() const
 // wxGenericTreeCtrl implementation
 // -----------------------------------------------------------------------------
 
-IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl, wxScrolledWindow)
+IMPLEMENT_DYNAMIC_CLASS(wxGenericTreeCtrl, wxControl)
 
-BEGIN_EVENT_TABLE(wxGenericTreeCtrl,wxScrolledWindow)
+BEGIN_EVENT_TABLE(wxGenericTreeCtrl, wxTreeCtrlBase)
     EVT_PAINT          (wxGenericTreeCtrl::OnPaint)
     EVT_MOUSE_EVENTS   (wxGenericTreeCtrl::OnMouse)
     EVT_CHAR           (wxGenericTreeCtrl::OnChar)
@@ -721,7 +741,10 @@ IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxGenericTreeCtrl)
 
 void wxGenericTreeCtrl::Init()
 {
-    m_current = m_key_current = m_anchor = m_select_me = (wxGenericTreeItem *) NULL;
+    m_current =
+    m_key_current =
+    m_anchor =
+    m_select_me = (wxGenericTreeItem *) NULL;
     m_hasFocus = false;
     m_dirty = false;
 
@@ -747,10 +770,8 @@ void wxGenericTreeCtrl::Init()
                                  wxSOLID
                               );
 
-    m_imageListNormal = m_imageListButtons =
-    m_imageListState = (wxImageList *) NULL;
-    m_ownsImageListNormal = m_ownsImageListButtons =
-    m_ownsImageListState = false;
+    m_imageListButtons = NULL;
+    m_ownsImageListButtons = false;
 
     m_dragCount = 0;
     m_isDragging = false;
@@ -786,7 +807,7 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
                                const wxPoint& pos,
                                const wxSize& size,
                                long style,
-                               const wxValidator& wxVALIDATOR_PARAM(validator),
+                               const wxValidator& validator,
                                const wxString& name )
 {
 #ifdef __WXMAC__
@@ -799,8 +820,11 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
         style |= wxTR_ROW_LINES;
 #endif // __WXMAC__
 
-    wxScrolledWindow::Create( parent, id, pos, size,
-                              style|wxHSCROLL|wxVSCROLL, name );
+    if ( !wxControl::Create( parent, id, pos, size,
+                             style|wxHSCROLL|wxVSCROLL,
+                             validator,
+                             name ) )
+        return false;
 
     // If the tree display has no buttons, but does have
     // connecting lines, we can use a narrower layout.
@@ -811,17 +835,12 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
         m_spacing = 10;
     }
 
-#if wxUSE_VALIDATORS
-    SetValidator( validator );
-#endif
-
     wxVisualAttributes attr = GetDefaultAttributes();
     SetOwnForegroundColour( attr.colFg );
     SetOwnBackgroundColour( attr.colBg );
     if (!m_hasFont)
         SetOwnFont(attr.font);
 
-//  m_dottedPen = wxPen( "grey", 0, wxDOT );  too slow under XFree86
     m_dottedPen = wxPen( wxT("grey"), 0, 0 );
 
     SetBestSize(size);
@@ -839,10 +858,6 @@ wxGenericTreeCtrl::~wxGenericTreeCtrl()
     delete m_renameTimer;
     delete m_findTimer;
 
-    if (m_ownsImageListNormal)
-        delete m_imageListNormal;
-    if (m_ownsImageListState)
-        delete m_imageListState;
     if (m_ownsImageListButtons)
         delete m_imageListButtons;
 }
@@ -851,7 +866,7 @@ wxGenericTreeCtrl::~wxGenericTreeCtrl()
 // accessors
 // -----------------------------------------------------------------------------
 
-size_t wxGenericTreeCtrl::GetCount() const
+unsigned int wxGenericTreeCtrl::GetCount() const
 {
     if ( !m_anchor )
     {
@@ -859,7 +874,7 @@ size_t wxGenericTreeCtrl::GetCount() const
         return 0;
     }
 
-    size_t count = m_anchor->GetChildrenCount();
+    unsigned int count = m_anchor->GetChildrenCount();
     if ( !HasFlag(wxTR_HIDE_ROOT) )
     {
         // take the root itself into account
@@ -875,12 +890,6 @@ void wxGenericTreeCtrl::SetIndent(unsigned int indent)
     m_dirty = true;
 }
 
-void wxGenericTreeCtrl::SetSpacing(unsigned int spacing)
-{
-    m_spacing = (unsigned short) spacing;
-    m_dirty = true;
-}
-
 size_t
 wxGenericTreeCtrl::GetChildrenCount(const wxTreeItemId& item,
                                     bool recursively) const
@@ -1065,7 +1074,7 @@ void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font
 
 bool wxGenericTreeCtrl::SetFont( const wxFont &font )
 {
-    wxScrolledWindow::SetFont(font);
+    wxTreeCtrlBase::SetFont(font);
 
     m_normalFont = font ;
     m_boldFont = wxFont(m_normalFont.GetPointSize(),
@@ -1393,10 +1402,11 @@ wxTreeItemId wxGenericTreeCtrl::FindItem(const wxTreeItemId& idParent,
 // -----------------------------------------------------------------------------
 
 wxTreeItemId wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId& parentId,
-                                      size_t previous,
-                                      const wxString& text,
-                                      int image, int selImage,
-                                      wxTreeItemData *data)
+                                             size_t previous,
+                                             const wxString& text,
+                                             int image,
+                                             int selImage,
+                                             wxTreeItemData *data)
 {
     wxGenericTreeItem *parent = (wxGenericTreeItem*) parentId.m_pItem;
     if ( !parent )
@@ -1415,14 +1425,16 @@ wxTreeItemId wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId& parentId,
         data->m_pItem = item;
     }
 
-    parent->Insert( item, previous );
+    parent->Insert( item, previous == (size_t)-1 ? parent->GetChildren().size()
+                                                 : previous );
 
     return item;
 }
 
 wxTreeItemId wxGenericTreeCtrl::AddRoot(const wxString& text,
-                                 int image, int selImage,
-                                 wxTreeItemData *data)
+                                        int image,
+                                        int selImage,
+                                        wxTreeItemData *data)
 {
     wxCHECK_MSG( !m_anchor, wxTreeItemId(), wxT("tree can have only one root") );
 
@@ -1453,19 +1465,11 @@ wxTreeItemId wxGenericTreeCtrl::AddRoot(const wxString& text,
     return m_anchor;
 }
 
-wxTreeItemId wxGenericTreeCtrl::PrependItem(const wxTreeItemId& parent,
-                                     const wxString& text,
-                                     int image, int selImage,
-                                     wxTreeItemData *data)
-{
-    return DoInsertItem(parent, 0u, text, image, selImage, data);
-}
-
-wxTreeItemId wxGenericTreeCtrl::InsertItem(const wxTreeItemId& parentId,
-                                    const wxTreeItemId& idPrevious,
-                                    const wxString& text,
-                                    int image, int selImage,
-                                    wxTreeItemData *data)
+wxTreeItemId wxGenericTreeCtrl::DoInsertAfter(const wxTreeItemId& parentId,
+                                              const wxTreeItemId& idPrevious,
+                                              const wxString& text,
+                                              int image, int selImage,
+                                              wxTreeItemData *data)
 {
     wxGenericTreeItem *parent = (wxGenericTreeItem*) parentId.m_pItem;
     if ( !parent )
@@ -1485,37 +1489,6 @@ wxTreeItemId wxGenericTreeCtrl::InsertItem(const wxTreeItemId& parentId,
     return DoInsertItem(parentId, (size_t)++index, text, image, selImage, data);
 }
 
-wxTreeItemId wxGenericTreeCtrl::InsertItem(const wxTreeItemId& parentId,
-                                    size_t before,
-                                    const wxString& text,
-                                    int image, int selImage,
-                                    wxTreeItemData *data)
-{
-    wxGenericTreeItem *parent = (wxGenericTreeItem*) parentId.m_pItem;
-    if ( !parent )
-    {
-        // should we give a warning here?
-        return AddRoot(text, image, selImage, data);
-    }
-
-    return DoInsertItem(parentId, before, text, image, selImage, data);
-}
-
-wxTreeItemId wxGenericTreeCtrl::AppendItem(const wxTreeItemId& parentId,
-                                    const wxString& text,
-                                    int image, int selImage,
-                                    wxTreeItemData *data)
-{
-    wxGenericTreeItem *parent = (wxGenericTreeItem*) parentId.m_pItem;
-    if ( !parent )
-    {
-        // should we give a warning here?
-        return AddRoot(text, image, selImage, data);
-    }
-
-    return DoInsertItem( parent, parent->GetChildren().Count(), text,
-                         image, selImage, data);
-}
 
 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item)
 {
@@ -1887,8 +1860,6 @@ void wxGenericTreeCtrl::DoSelectItem(const wxTreeItemId& itemId,
         parent = GetItemParent( parent );
     }
 
-    EnsureVisible( itemId );
-
     // ctrl press
     if (unselect_others)
     {
@@ -1920,6 +1891,11 @@ void wxGenericTreeCtrl::DoSelectItem(const wxTreeItemId& itemId,
         RefreshLine( m_current );
     }
 
+    // This can cause idle processing to select the root
+    // if no item is selected, so it must be after the
+    // selection is set
+    EnsureVisible( itemId );
+
     event.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED);
     GetEventHandler()->ProcessEvent( event );
 }
@@ -2066,12 +2042,6 @@ static int LINKAGEMODE tree_ctrl_compare_func(wxGenericTreeItem **item1,
     return s_treeBeingSorted->OnCompareItems(*item1, *item2);
 }
 
-int wxGenericTreeCtrl::OnCompareItems(const wxTreeItemId& item1,
-                               const wxTreeItemId& item2)
-{
-    return wxStrcmp(GetItemText(item1), GetItemText(item2));
-}
-
 void wxGenericTreeCtrl::SortChildren(const wxTreeItemId& itemId)
 {
     wxCHECK_RET( itemId.IsOk(), wxT("invalid tree item") );
@@ -2093,21 +2063,6 @@ void wxGenericTreeCtrl::SortChildren(const wxTreeItemId& itemId)
     //else: don't make the tree dirty as nothing changed
 }
 
-wxImageList *wxGenericTreeCtrl::GetImageList() const
-{
-    return m_imageListNormal;
-}
-
-wxImageList *wxGenericTreeCtrl::GetButtonsImageList() const
-{
-    return m_imageListButtons;
-}
-
-wxImageList *wxGenericTreeCtrl::GetStateImageList() const
-{
-    return m_imageListState;
-}
-
 void wxGenericTreeCtrl::CalculateLineHeight()
 {
     wxClientDC dc(this);
@@ -2175,18 +2130,6 @@ void wxGenericTreeCtrl::SetButtonsImageList(wxImageList *imageList)
     CalculateLineHeight();
 }
 
-void wxGenericTreeCtrl::AssignImageList(wxImageList *imageList)
-{
-    SetImageList(imageList);
-    m_ownsImageListNormal = true;
-}
-
-void wxGenericTreeCtrl::AssignStateImageList(wxImageList *imageList)
-{
-    SetStateImageList(imageList);
-    m_ownsImageListState = true;
-}
-
 void wxGenericTreeCtrl::AssignButtonsImageList(wxImageList *imageList)
 {
     SetButtonsImageList(imageList);
@@ -2243,7 +2186,7 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
         if ( m_imageListNormal )
         {
             m_imageListNormal->GetSize( image, image_w, image_h );
-            image_w += 4;
+            image_w += MARGIN_BETWEEN_IMAGE_AND_TEXT;
         }
         else
         {
@@ -2282,7 +2225,7 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
         }
         else
         {
-            colBg = m_backgroundColour;
+            colBg = GetBackgroundColour();
         }
         dc.SetBrush(wxBrush(colBg, wxSOLID));
     }
@@ -2383,7 +2326,7 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level
 
     if (IsExposed(exposed_x, exposed_y, 10000, h))  // 10000 = very much
     {
-        wxPen *pen =
+        const wxPen *pen =
 #ifndef __WXMAC__
             // don't draw rect outline if we already have the
             // background color under Mac
@@ -2392,7 +2335,15 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level
             wxTRANSPARENT_PEN;
 
         wxColour colText;
-        if ( item->IsSelected() )
+        if ( item->IsSelected()
+#ifdef __WXMAC__
+            // On wxMac, if the tree doesn't have the focus we draw an empty
+            // rectangle, so we want to make sure that the text is visible
+            // against the normal background, not the highlightbackground, so
+            // don't use the highlight text colour unless we have the focus.
+             && m_hasFocus
+#endif
+            )
         {
             colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
         }
@@ -2696,23 +2647,23 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
                 wxRect ItemRect;
                 GetBoundingRect(m_current, ItemRect, true);
 
-                wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_MENU, GetId() );
-                event.m_item = m_current;
+                wxTreeEvent eventMenu( wxEVT_COMMAND_TREE_ITEM_MENU, GetId() );
+                eventMenu.m_item = m_current;
                 // Use the left edge, vertical middle
-                event.m_pointDrag = wxPoint(ItemRect.GetX(),
-                                            ItemRect.GetY() + ItemRect.GetHeight() / 2);
-                event.SetEventObject( this );
-                GetEventHandler()->ProcessEvent( event );
+                eventMenu.m_pointDrag = wxPoint(ItemRect.GetX(),
+                                                ItemRect.GetY() + ItemRect.GetHeight() / 2);
+                eventMenu.SetEventObject( this );
+                GetEventHandler()->ProcessEvent( eventMenu );
                 break;
             }
         case ' ':
         case WXK_RETURN:
             if ( !event.HasModifiers() )
             {
-                wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
-                event.m_item = m_current;
-                event.SetEventObject( this );
-                GetEventHandler()->ProcessEvent( event );
+                wxTreeEvent eventAct( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
+                eventAct.m_item = m_current;
+                eventAct.SetEventObject( this );
+                GetEventHandler()->ProcessEvent( eventAct );
             }
 
             // in any case, also generate the normal key event for this key,
@@ -2900,7 +2851,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
     }
 }
 
-wxTreeItemId wxGenericTreeCtrl::HitTest(const wxPoint& point, int& flags)
+wxTreeItemId wxGenericTreeCtrl::DoTreeHitTest(const wxPoint& point, int& flags)
 {
     // JACS: removed wxYieldIfNeeded() because it can cause the window
     // to be deleted from under us if a close window event is pending
@@ -2933,27 +2884,43 @@ wxTreeItemId wxGenericTreeCtrl::HitTest(const wxPoint& point, int& flags)
 // get the bounding rectangle of the item (or of its label only)
 bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId& item,
                                         wxRect& rect,
-                                        bool WXUNUSED(textOnly)) const
+                                        bool textOnly) const
 {
     wxCHECK_MSG( item.IsOk(), false, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") );
 
     wxGenericTreeItem *i = (wxGenericTreeItem*) item.m_pItem;
 
-    int startX, startY;
-    GetViewStart(& startX, & startY);
+    if ( textOnly )
+    {
+        rect.x = i->GetX();
+        rect.width = i->GetWidth();
 
-    rect.x = i->GetX() - startX*PIXELS_PER_UNIT;
-    rect.y = i->GetY() - startY*PIXELS_PER_UNIT;
-    rect.width = i->GetWidth();
-    //rect.height = i->GetHeight();
+        if ( m_imageListNormal )
+        {
+            int image_w, image_h;
+            m_imageListNormal->GetSize( 0, image_w, image_h );
+            rect.width += image_w + MARGIN_BETWEEN_IMAGE_AND_TEXT;
+        }
+    }
+    else // the entire line
+    {
+        rect.x = 0;
+        rect.width = GetClientSize().x;
+    }
+
+    rect.y = i->GetY();
     rect.height = GetLineHeight(i);
 
+    // we have to return the logical coordinates, not physical ones
+    rect.SetTopLeft(CalcScrolledPosition(rect.GetTopLeft()));
+
     return true;
 }
 
-void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
+wxTextCtrl *wxGenericTreeCtrl::EditLabel(const wxTreeItemId& item,
+                                  wxClassInfo * WXUNUSED(textCtrlClass))
 {
-    wxCHECK_RET( item.IsOk(), _T("can't edit an invalid item") );
+    wxCHECK_MSG( item.IsOk(), NULL, _T("can't edit an invalid item") );
 
     wxGenericTreeItem *itemEdit = (wxGenericTreeItem *)item.m_pItem;
 
@@ -2963,7 +2930,7 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
     if ( GetEventHandler()->ProcessEvent( te ) && !te.IsAllowed() )
     {
         // vetoed by user
-        return;
+        return NULL;
     }
 
     // We have to call this here because the label in
@@ -2976,9 +2943,12 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
         wxYieldIfNeeded();
 #endif
 
+    // TODO: use textCtrlClass here to create the control of correct class
     m_textCtrl = new wxTreeTextCtrl(this, itemEdit);
 
     m_textCtrl->SetFocus();
+
+    return m_textCtrl;
 }
 
 // returns a pointer to the text edit control if the item is being
@@ -2989,6 +2959,14 @@ wxTextCtrl* wxGenericTreeCtrl::GetEditControl() const
     return m_textCtrl;
 }
 
+void wxGenericTreeCtrl::EndEditLabel(const wxTreeItemId& WXUNUSED(item),
+                                     bool discardChanges)
+{
+    wxCHECK_RET( m_textCtrl, _T("not editing label") );
+
+    m_textCtrl->EndEdit(discardChanges);
+}
+
 bool wxGenericTreeCtrl::OnRenameAccept(wxGenericTreeItem *item,
                                        const wxString& value)
 {
@@ -3015,7 +2993,7 @@ void wxGenericTreeCtrl::OnRenameCancelled(wxGenericTreeItem *item)
 
 void wxGenericTreeCtrl::OnRenameTimer()
 {
-    Edit( m_current );
+    EditLabel( m_current );
 }
 
 void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
@@ -3117,7 +3095,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
         wxTreeEvent nevent( command, GetId() );
         nevent.m_item = m_current;
         nevent.SetEventObject(this);
-        nevent.SetPoint(pt);
+        nevent.SetPoint(CalcScrolledPosition(pt));
 
         // by default the dragging is not supported, the user code must
         // explicitly allow the event for it to take place
@@ -3168,6 +3146,8 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
     }
     else if ( (event.LeftUp() || event.RightUp()) && m_isDragging )
     {
+        ReleaseMouse();
+
         // erase the highlighting
         DrawDropEffect(m_dropTarget);
 
@@ -3179,19 +3159,17 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
         }
 
         // generate the drag end event
-        wxTreeEvent event(wxEVT_COMMAND_TREE_END_DRAG, GetId());
+        wxTreeEvent eventEndDrag(wxEVT_COMMAND_TREE_END_DRAG, GetId());
 
-        event.m_item = item;
-        event.m_pointDrag = pt;
-        event.SetEventObject(this);
+        eventEndDrag.m_item = item;
+        eventEndDrag.m_pointDrag = CalcScrolledPosition(pt);
+        eventEndDrag.SetEventObject(this);
 
-        (void)GetEventHandler()->ProcessEvent(event);
+        (void)GetEventHandler()->ProcessEvent(eventEndDrag);
 
         m_isDragging = false;
         m_dropTarget = (wxGenericTreeItem *)NULL;
 
-        ReleaseMouse();
-
         SetCursor(m_oldCursor);
 
 #if defined( __WXMSW__ ) || defined(__WXMAC__)
@@ -3405,7 +3383,7 @@ void wxGenericTreeCtrl::CalculateSize( wxGenericTreeItem *item, wxDC &dc )
         if ( m_imageListNormal )
         {
             m_imageListNormal->GetSize( image, image_w, image_h );
-            image_w += 4;
+            image_w += MARGIN_BETWEEN_IMAGE_AND_TEXT;
         }
     }
 
@@ -3542,7 +3520,7 @@ void wxGenericTreeCtrl::Thaw()
 {
     wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen tree control?") );
 
-    if ( !--m_freezeCount )
+    if ( --m_freezeCount == 0 )
     {
         Refresh();
     }
@@ -3584,15 +3562,6 @@ void wxGenericTreeCtrl::OnGetToolTip( wxTreeEvent &event )
 }
 
 
-wxSize wxGenericTreeCtrl::DoGetBestSize() const
-{
-    // something is better than nothing...
-    // 100x80 is what the MSW version will get from the default
-    // wxControl::DoGetBestSize
-    return wxSize(100,80);
-}
-
-
 // NOTE: If using the wxListBox visual attributes works everywhere then this can
 // be removed, as well as the #else case below.
 #define _USE_VISATTR 0
@@ -3635,13 +3604,4 @@ void wxGenericTreeCtrl::SetItemSelectedImage(const wxTreeItemId& item, int image
 
 #endif // WXWIN_COMPATIBILITY_2_4
 
-#if WXWIN_COMPATIBILITY_2_2
-
-wxTreeItemId wxGenericTreeCtrl::GetParent(const wxTreeItemId& item) const
-{
-    return GetItemParent( item );
-}
-
-#endif  // WXWIN_COMPATIBILITY_2_2
-
 #endif // wxUSE_TREECTRL