]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/treectlg.cpp
Various fixes for wxMotif
[wxWidgets.git] / src / generic / treectlg.cpp
index 3e1dcb049b2114cf476bf5411b6e605d1e36fcfd..113dbba5849aa0075eb86ebb93fd60c769ca3b1c 100644 (file)
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
-#pragma hdrstop
+    #pragma hdrstop
 #endif
 
 #endif
 
+#if wxUSE_TREECTRL
+
 #include "wx/generic/treectlg.h"
 #include "wx/imaglist.h"
 #include "wx/settings.h"
 #include "wx/generic/treectlg.h"
 #include "wx/imaglist.h"
 #include "wx/settings.h"
@@ -44,7 +46,7 @@
 
 class WXDLLEXPORT wxGenericTreeItem;
 
 
 class WXDLLEXPORT wxGenericTreeItem;
 
-WX_DEFINE_ARRAY(wxGenericTreeItem *, wxArrayGenericTreeItems);
+WX_DEFINE_EXPORTED_ARRAY(wxGenericTreeItem *, wxArrayGenericTreeItems);
 //WX_DEFINE_OBJARRAY(wxArrayTreeItemIds);
 
 // ----------------------------------------------------------------------------
 //WX_DEFINE_OBJARRAY(wxArrayTreeItemIds);
 
 // ----------------------------------------------------------------------------
@@ -84,11 +86,12 @@ public:
                     const wxString &value = wxEmptyString,
                     const wxPoint &pos = wxDefaultPosition,
                     const wxSize &size = wxDefaultSize,
                     const wxString &value = wxEmptyString,
                     const wxPoint &pos = wxDefaultPosition,
                     const wxSize &size = wxDefaultSize,
-                    int style = 0,
+                    int style = wxSIMPLE_BORDER,
                     const wxValidator& validator = wxDefaultValidator,
                     const wxString &name = wxTextCtrlNameStr );
 
     void OnChar( wxKeyEvent &event );
                     const wxValidator& validator = wxDefaultValidator,
                     const wxString &name = wxTextCtrlNameStr );
 
     void OnChar( wxKeyEvent &event );
+    void OnKeyUp( wxKeyEvent &event );
     void OnKillFocus( wxFocusEvent &event );
 
 private:
     void OnKillFocus( wxFocusEvent &event );
 
 private:
@@ -178,10 +181,10 @@ public:
 
     // status inquiries
     bool HasChildren() const { return !m_children.IsEmpty(); }
 
     // status inquiries
     bool HasChildren() const { return !m_children.IsEmpty(); }
-    bool IsSelected()  const { return m_hasHilight; }
+    bool IsSelected()  const { return m_hasHilight != 0; }
     bool IsExpanded()  const { return !m_isCollapsed; }
     bool HasPlus()     const { return m_hasPlus || HasChildren(); }
     bool IsExpanded()  const { return !m_isCollapsed; }
     bool HasPlus()     const { return m_hasPlus || HasChildren(); }
-    bool IsBold()      const { return m_isBold; }
+    bool IsBold()      const { return m_isBold != 0; }
 
     // attributes
         // get them - may be NULL
 
     // attributes
         // get them - may be NULL
@@ -266,6 +269,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxTreeTextCtrl,wxTextCtrl);
 
 BEGIN_EVENT_TABLE(wxTreeTextCtrl,wxTextCtrl)
     EVT_CHAR           (wxTreeTextCtrl::OnChar)
 
 BEGIN_EVENT_TABLE(wxTreeTextCtrl,wxTextCtrl)
     EVT_CHAR           (wxTreeTextCtrl::OnChar)
+    EVT_KEY_UP         (wxTreeTextCtrl::OnKeyUp)
     EVT_KILL_FOCUS     (wxTreeTextCtrl::OnKillFocus)
 END_EVENT_TABLE()
 
     EVT_KILL_FOCUS     (wxTreeTextCtrl::OnKillFocus)
 END_EVENT_TABLE()
 
@@ -296,28 +300,43 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event )
     {
         (*m_accept) = TRUE;
         (*m_res) = GetValue();
     {
         (*m_accept) = TRUE;
         (*m_res) = GetValue();
-        
+
         if (!wxPendingDelete.Member(this))
             wxPendingDelete.Append(this);
 
         if ((*m_accept) && ((*m_res) != m_startValue))
             m_owner->OnRenameAccept();
         if (!wxPendingDelete.Member(this))
             wxPendingDelete.Append(this);
 
         if ((*m_accept) && ((*m_res) != m_startValue))
             m_owner->OnRenameAccept();
-            
+
         return;
     }
     if (event.m_keyCode == WXK_ESCAPE)
     {
         (*m_accept) = FALSE;
         (*m_res) = "";
         return;
     }
     if (event.m_keyCode == WXK_ESCAPE)
     {
         (*m_accept) = FALSE;
         (*m_res) = "";
-        
+
         if (!wxPendingDelete.Member(this))
             wxPendingDelete.Append(this);
         if (!wxPendingDelete.Member(this))
             wxPendingDelete.Append(this);
-            
+
         return;
     }
     event.Skip();
 }
 
         return;
     }
     event.Skip();
 }
 
+void wxTreeTextCtrl::OnKeyUp( wxKeyEvent &event )
+{
+    // auto-grow the textctrl:
+    wxSize parentSize = m_owner->GetSize();
+    wxPoint myPos = GetPosition();
+    wxSize mySize = GetSize();
+    int sx, sy;
+    GetTextExtent(GetValue() + _T("MM"), &sx, &sy);
+    if (myPos.x + sx > parentSize.x) sx = parentSize.x - myPos.x;
+    if (mySize.x > sx) sx = mySize.x;
+    SetSize(sx, -1);
+
+    event.Skip();
+}
+
 void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
 {
     if (!wxPendingDelete.Member(this))
 void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
 {
     if (!wxPendingDelete.Member(this))
@@ -615,6 +634,8 @@ void wxGenericTreeCtrl::Init()
 
     m_imageListNormal =
     m_imageListState = (wxImageList *) NULL;
 
     m_imageListNormal =
     m_imageListState = (wxImageList *) NULL;
+    m_ownsImageListNormal =
+    m_ownsImageListState = FALSE;
 
     m_dragCount = 0;
     m_isDragging = FALSE;
 
     m_dragCount = 0;
     m_isDragging = FALSE;
@@ -638,8 +659,6 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, wxWindowID id,
                         const wxValidator &validator,
                         const wxString& name )
 {
                         const wxValidator &validator,
                         const wxString& name )
 {
-    Init();
-
     wxScrolledWindow::Create( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name );
 
 #if wxUSE_VALIDATORS
     wxScrolledWindow::Create( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name );
 
 #if wxUSE_VALIDATORS
@@ -647,6 +666,7 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, wxWindowID id,
 #endif
 
     SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) );
 #endif
 
     SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) );
+
 //  m_dottedPen = wxPen( "grey", 0, wxDOT );  too slow under XFree86
     m_dottedPen = wxPen( "grey", 0, 0 );
 
 //  m_dottedPen = wxPen( "grey", 0, wxDOT );  too slow under XFree86
     m_dottedPen = wxPen( "grey", 0, 0 );
 
@@ -660,6 +680,8 @@ wxGenericTreeCtrl::~wxGenericTreeCtrl()
     DeleteAllItems();
 
     delete m_renameTimer;
     DeleteAllItems();
 
     delete m_renameTimer;
+    if (m_ownsImageListNormal) delete m_imageListNormal;
+    if (m_ownsImageListState) delete m_imageListState;
 }
 
 // -----------------------------------------------------------------------------
 }
 
 // -----------------------------------------------------------------------------
@@ -799,13 +821,53 @@ void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font
     RefreshLine(pItem);
 }
 
     RefreshLine(pItem);
 }
 
+bool wxGenericTreeCtrl::SetFont( const wxFont &font )
+{
+    wxScrolledWindow::SetFont(font);
+
+    m_normalFont = font ;
+    m_boldFont = wxFont( m_normalFont.GetPointSize(),
+                            m_normalFont.GetFamily(),
+                            m_normalFont.GetStyle(),
+                            wxBOLD,
+                            m_normalFont.GetUnderlined());
+
+    return TRUE;
+}
+
+
 // -----------------------------------------------------------------------------
 // item status inquiries
 // -----------------------------------------------------------------------------
 
 // -----------------------------------------------------------------------------
 // item status inquiries
 // -----------------------------------------------------------------------------
 
-bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId& WXUNUSED(item)) const
+bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId& item) const
 {
 {
-    wxFAIL_MSG(wxT("not implemented"));
+    wxCHECK_MSG( item.IsOk(), FALSE, wxT("invalid tree item") );
+
+    // An item is only visible if it's not a descendant of a collapsed item
+    wxGenericTreeItem *pItem = (wxGenericTreeItem*) item.m_pItem;
+    wxGenericTreeItem* parent = pItem->GetParent();
+    while (parent)
+    {
+        if (!parent->IsExpanded())
+            return FALSE;
+        parent = parent->GetParent();
+    }
+
+    int startX, startY;
+    GetViewStart(& startX, & startY);
+
+    wxSize clientSize = GetClientSize();
+
+    wxRect rect;
+    if (!GetBoundingRect(item, rect))
+        return FALSE;
+    if (rect.GetWidth() == 0 || rect.GetHeight() == 0)
+        return FALSE;
+    if (rect.GetBottom() < 0 || rect.GetTop() > clientSize.y)
+        return FALSE;
+    if (rect.GetRight() < 0 || rect.GetLeft() > clientSize.x)
+        return FALSE;
 
     return TRUE;
 }
 
     return TRUE;
 }
@@ -921,19 +983,70 @@ wxTreeItemId wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const
                     : wxTreeItemId(siblings[(size_t)(index - 1)]);
 }
 
                     : wxTreeItemId(siblings[(size_t)(index - 1)]);
 }
 
-wxTreeItemId wxGenericTreeCtrl::GetFirstVisibleItem() const
+// Only for internal use right now, but should probably be public
+wxTreeItemId wxGenericTreeCtrl::GetNext(const wxTreeItemId& item) const
+{
+  wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
+
+  wxGenericTreeItem *i = (wxGenericTreeItem*) item.m_pItem;
+
+  // First see if there are any children.
+  wxArrayGenericTreeItems& children = i->GetChildren();
+  if (children.GetCount() > 0)
+  {
+     return children.Item(0);
+  }
+  else
+  {
+     // Try a sibling of this or ancestor instead
+     wxTreeItemId p = item;
+     wxTreeItemId toFind;
+     do
+     {
+        toFind = GetNextSibling(p);
+        p = GetParent(p);
+     } while (p.IsOk() && !toFind.IsOk());
+     return toFind;
+  }
+}
+
+wxTreeItemId wxGenericTreeCtrl::GetPrev(const wxTreeItemId& item) const
 {
 {
+  wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
+
   wxFAIL_MSG(wxT("not implemented"));
 
   return wxTreeItemId();
 }
 
   wxFAIL_MSG(wxT("not implemented"));
 
   return wxTreeItemId();
 }
 
+wxTreeItemId wxGenericTreeCtrl::GetFirstVisibleItem() const
+{
+  wxTreeItemId id = GetRootItem();
+  if (!id.IsOk())
+    return id;
+
+  do
+  {
+    if (IsVisible(id))
+        return id;
+    id = GetNext(id);
+  } while (id.IsOk());
+
+  return wxTreeItemId();
+}
+
 wxTreeItemId wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId& item) const
 {
   wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
 
 wxTreeItemId wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId& item) const
 {
   wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
 
-  wxFAIL_MSG(wxT("not implemented"));
+  wxTreeItemId id = item;
+  while (id.IsOk())
+  {
+      id = GetNext(id);
 
 
+      if (id.IsOk() && IsVisible(id))
+          return id;
+  }
   return wxTreeItemId();
 }
 
   return wxTreeItemId();
 }
 
@@ -969,7 +1082,7 @@ wxTreeItemId wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId& parentId,
 
     if ( data != NULL )
     {
 
     if ( data != NULL )
     {
-        data->m_pItem = item;
+        data->m_pItem = (long) item;
     }
 
     parent->Insert( item, previous );
     }
 
     parent->Insert( item, previous );
@@ -990,7 +1103,7 @@ wxTreeItemId wxGenericTreeCtrl::AddRoot(const wxString& text,
                                    image, selImage, data);
     if ( data != NULL )
     {
                                    image, selImage, data);
     if ( data != NULL )
     {
-        data->m_pItem = m_anchor;
+        data->m_pItem = (long) m_anchor;
     }
 
     if (!HasFlag(wxTR_MULTIPLE))
     }
 
     if (!HasFlag(wxTR_MULTIPLE))
@@ -1067,7 +1180,7 @@ wxTreeItemId wxGenericTreeCtrl::AppendItem(const wxTreeItemId& parentId,
 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item)
 {
     wxTreeEvent event( wxEVT_COMMAND_TREE_DELETE_ITEM, GetId() );
 void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item)
 {
     wxTreeEvent event( wxEVT_COMMAND_TREE_DELETE_ITEM, GetId() );
-    event.m_item = item;
+    event.m_item = (long) item;
     event.SetEventObject( this );
     ProcessEvent( event );
 }
     event.SetEventObject( this );
     ProcessEvent( event );
 }
@@ -1146,7 +1259,7 @@ void wxGenericTreeCtrl::Expand(const wxTreeItemId& itemId)
         return;
 
     wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_EXPANDING, GetId() );
         return;
 
     wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_EXPANDING, GetId() );
-    event.m_item = item;
+    event.m_item = (long) item;
     event.SetEventObject( this );
 
     if ( ProcessEvent( event ) && !event.IsAllowed() )
     event.SetEventObject( this );
 
     if ( ProcessEvent( event ) && !event.IsAllowed() )
@@ -1188,7 +1301,7 @@ void wxGenericTreeCtrl::Collapse(const wxTreeItemId& itemId)
         return;
 
     wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING, GetId() );
         return;
 
     wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING, GetId() );
-    event.m_item = item;
+    event.m_item = (long) item;
     event.SetEventObject( this );
     if ( ProcessEvent( event ) && !event.IsAllowed() )
     {
     event.SetEventObject( this );
     if ( ProcessEvent( event ) && !event.IsAllowed() )
     {
@@ -1364,8 +1477,8 @@ void wxGenericTreeCtrl::SelectItem(const wxTreeItemId& itemId,
     }
 
     wxTreeEvent event( wxEVT_COMMAND_TREE_SEL_CHANGING, GetId() );
     }
 
     wxTreeEvent event( wxEVT_COMMAND_TREE_SEL_CHANGING, GetId() );
-    event.m_item = item;
-    event.m_itemOld = m_current;
+    event.m_item = (long) item;
+    event.m_itemOld = (long) m_current;
     event.SetEventObject( this );
     // TODO : Here we don't send any selection mode yet !
 
     event.SetEventObject( this );
     // TODO : Here we don't send any selection mode yet !
 
@@ -1462,7 +1575,7 @@ void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId &item)
     // We have to call this here because the label in
     // question might just have been added and no screen
     // update taken place.
     // 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();
+    if (m_dirty) wxYieldIfNeeded();
 
     wxGenericTreeItem *gitem = (wxGenericTreeItem*) item.m_pItem;
 
 
     wxGenericTreeItem *gitem = (wxGenericTreeItem*) item.m_pItem;
 
@@ -1471,7 +1584,7 @@ void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId &item)
 
     int start_x = 0;
     int start_y = 0;
 
     int start_x = 0;
     int start_y = 0;
-    ViewStart( &start_x, &start_y );
+    GetViewStart( &start_x, &start_y );
     start_y *= PIXELS_PER_UNIT;
 
     int client_h = 0;
     start_y *= PIXELS_PER_UNIT;
 
     int client_h = 0;
@@ -1555,7 +1668,10 @@ wxImageList *wxGenericTreeCtrl::GetStateImageList() const
 
 void wxGenericTreeCtrl::SetImageList(wxImageList *imageList)
 {
 
 void wxGenericTreeCtrl::SetImageList(wxImageList *imageList)
 {
+    if (m_ownsImageListNormal) delete m_imageListNormal;
+
     m_imageListNormal = imageList;
     m_imageListNormal = imageList;
+    m_ownsImageListNormal = FALSE;
 
     if ( !m_imageListNormal )
         return;
 
     if ( !m_imageListNormal )
         return;
@@ -1582,7 +1698,21 @@ void wxGenericTreeCtrl::SetImageList(wxImageList *imageList)
 
 void wxGenericTreeCtrl::SetStateImageList(wxImageList *imageList)
 {
 
 void wxGenericTreeCtrl::SetStateImageList(wxImageList *imageList)
 {
+    if (m_ownsImageListState) delete m_imageListState;
     m_imageListState = imageList;
     m_imageListState = imageList;
+    m_ownsImageListState = FALSE;
+}
+
+void wxGenericTreeCtrl::AssignImageList(wxImageList *imageList)
+{
+    SetImageList(imageList);
+    m_ownsImageListNormal = TRUE;
+}
+
+void wxGenericTreeCtrl::AssignStateImageList(wxImageList *imageList)
+{
+    SetStateImageList(imageList);
+    m_ownsImageListState = TRUE;
 }
 
 // -----------------------------------------------------------------------------
 }
 
 // -----------------------------------------------------------------------------
@@ -1658,7 +1788,22 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
         dc.SetBrush(wxBrush(colBg, wxSOLID));
     }
 
         dc.SetBrush(wxBrush(colBg, wxSOLID));
     }
 
-    dc.DrawRectangle( item->GetX()-2, item->GetY(), item->GetWidth()+2, total_h );
+    int offset = 0;
+    if (HasFlag(wxTR_ROW_LINES)) offset = 1;
+
+    if (item->IsSelected() && image != NO_IMAGE)
+    {
+        // If it's selected, and there's an image, then we should
+        // take care to leave the area under the image painted in the
+        // background colour.
+        dc.DrawRectangle( item->GetX() + image_w - 2, item->GetY()+offset, 
+                                         item->GetWidth() - image_w + 2, total_h-offset );
+    }
+    else
+    {
+        dc.DrawRectangle( item->GetX()-2, item->GetY()+offset, 
+                                         item->GetWidth()+2, total_h-offset );
+    }
 
     if ( image != NO_IMAGE )
     {
 
     if ( image != NO_IMAGE )
     {
@@ -1683,46 +1828,79 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
 // Now y stands for the top of the item, whereas it used to stand for middle !
 void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y )
 {
 // Now y stands for the top of the item, whereas it used to stand for middle !
 void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &y )
 {
-    int horizX = level*m_indent;
+    int x = (level+1)*m_indent;
 
 
-    item->SetX( horizX+m_indent+m_spacing );
+    item->SetX( x+m_spacing );
     item->SetY( y );
 
     int oldY = y;
     y+=GetLineHeight(item)/2;
 
     item->SetY( y );
 
     int oldY = y;
     y+=GetLineHeight(item)/2;
 
-    item->SetCross( horizX+m_indent, y );
+    item->SetCross( x, y );
 
     int exposed_x = dc.LogicalToDeviceX( 0 );
     int exposed_y = dc.LogicalToDeviceY( item->GetY() );
 
 
     int exposed_x = dc.LogicalToDeviceX( 0 );
     int exposed_y = dc.LogicalToDeviceY( item->GetY() );
 
-    bool drawLines = ((GetWindowStyle() & wxTR_NO_LINES) == 0);
+    bool drawLines = (!HasFlag(wxTR_NO_LINES) && !HasFlag(wxTR_MAC_BUTTONS));
 
     if (IsExposed( exposed_x, exposed_y, 10000, GetLineHeight(item) ))  // 10000 = very much
     {
 
     if (IsExposed( exposed_x, exposed_y, 10000, GetLineHeight(item) ))  // 10000 = very much
     {
-        int startX = horizX;
-        int endX = horizX + (m_indent-5);
+        int startX = x - m_indent;
+        int endX = x-5;
 
 
-//        if (!item->HasChildren()) endX += (m_indent+5);
         if (!item->HasChildren()) endX += 20;
         if (!item->HasChildren()) endX += 20;
-
-        if (drawLines)
-            dc.DrawLine( startX, y, endX, y );
-
-        if (item->HasPlus())
+        
+        if (HasFlag( wxTR_MAC_BUTTONS ))
+        {              
+            if (item->HasPlus())
+            {
+                dc.SetPen( *wxBLACK_PEN );
+                dc.SetBrush( *m_hilightBrush );
+                
+                wxPoint button[3];
+                
+                if (item->IsExpanded())
+                {
+                    button[0].x = x-5;
+                    button[0].y = y-2;
+                    button[1].x = x+5;
+                    button[1].y = y-2;
+                    button[2].x = x;
+                    button[2].y = y+3;
+                }
+                else
+                {
+                    button[0].y = y-5;
+                    button[0].x = x-2;
+                    button[1].y = y+5;
+                    button[1].x = x-2;
+                    button[2].y = y;
+                    button[2].x = x+3;
+                }
+                dc.DrawPolygon( 3, button );
+                
+                dc.SetPen( m_dottedPen );
+            }
+        }
+        else
         {
             if (drawLines)
         {
             if (drawLines)
-                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.DrawLine( startX, y, endX, y );
 
 
-            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 );
+            if (item->HasPlus())
+            {
+                if (drawLines)
+                    dc.DrawLine( x+5, y, x+15, y );
+                dc.SetPen( *wxGREY_PEN );
+                dc.SetBrush( *wxWHITE_BRUSH );
+                dc.DrawRectangle( x-5, y-4, 11, 9 );
+
+                dc.SetPen( *wxBLACK_PEN );
+                dc.DrawLine( x-2, y, x+3, y );
+                if (!item->IsExpanded())
+                    dc.DrawLine( x, y-2, x, y+3 );
+                dc.SetPen( m_dottedPen );
+            }
         }
 
         wxPen *pen = wxTRANSPARENT_PEN;
         }
 
         wxPen *pen = wxTRANSPARENT_PEN;
@@ -1742,7 +1920,7 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level
             if ( attr && attr->HasTextColour() )
                 colText = attr->GetTextColour();
             else
             if ( attr && attr->HasTextColour() )
                 colText = attr->GetTextColour();
             else
-                colText = *wxBLACK;
+                colText = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT );
         }
 
         // prepare to draw
         }
 
         // prepare to draw
@@ -1752,6 +1930,13 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level
         // draw
         PaintItem(item, dc);
 
         // draw
         PaintItem(item, dc);
 
+        if (HasFlag( wxTR_ROW_LINES ))
+        {
+               dc.SetPen( *wxWHITE_PEN );
+               dc.DrawLine( 0, oldY, 10000, oldY );
+               dc.DrawLine( 0, oldY + GetLineHeight(item), 10000, oldY + GetLineHeight(item) );
+        }
+        
         // restore DC objects
         dc.SetBrush( *wxWHITE_BRUSH );
         dc.SetPen( m_dottedPen );
         // restore DC objects
         dc.SetBrush( *wxWHITE_BRUSH );
         dc.SetPen( m_dottedPen );
@@ -1780,7 +1965,7 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level
         {
             semiOldY+=GetLineHeight(children[--n])/2;
             if (drawLines)
         {
             semiOldY+=GetLineHeight(children[--n])/2;
             if (drawLines)
-                dc.DrawLine( horizX+m_indent, oldY+5, horizX+m_indent, semiOldY );
+                dc.DrawLine( x, oldY+5, x, semiOldY );
         }
     }
 }
         }
     }
 }
@@ -1946,7 +2131,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
         case WXK_RETURN:
             {
                 wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
         case WXK_RETURN:
             {
                 wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
-                event.m_item = m_current;
+                event.m_item = (long) m_current;
                 event.m_code = 0;
                 event.SetEventObject( this );
                 GetEventHandler()->ProcessEvent( event );
                 event.m_code = 0;
                 event.SetEventObject( this );
                 GetEventHandler()->ProcessEvent( event );
@@ -2091,7 +2276,9 @@ wxTreeItemId wxGenericTreeCtrl::HitTest(const wxPoint& point, int& flags)
     // We have to call this here because the label in
     // question might just have been added and no screen
     // update taken place.
     // 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();
+    // JACS: removed this because the yield can cause the window to be
+    // deleted from under us if a close window event is pending
+    // if (m_dirty) wxYieldIfNeeded();
 
     wxClientDC dc(this);
     PrepareDC(dc);
 
     wxClientDC dc(this);
     PrepareDC(dc);
@@ -2106,7 +2293,31 @@ wxTreeItemId wxGenericTreeCtrl::HitTest(const wxPoint& point, int& flags)
     if (point.y<0) flags|=wxTREE_HITTEST_ABOVE;
     if (point.y>h) flags|=wxTREE_HITTEST_BELOW;
 
     if (point.y<0) flags|=wxTREE_HITTEST_ABOVE;
     if (point.y>h) flags|=wxTREE_HITTEST_BELOW;
 
-    return m_anchor->HitTest( wxPoint(x, y), this, flags);
+    if (m_anchor)
+        return m_anchor->HitTest( wxPoint(x, y), this, flags);
+    else
+        return wxTreeItemId();
+}
+
+// get the bounding rectangle of the item (or of its label only)
+bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId& item,
+                         wxRect& rect,
+                         bool WXUNUSED(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);
+
+    rect.x = i->GetX() - startX*PIXELS_PER_UNIT;
+    rect.y = i->GetY() - startY*PIXELS_PER_UNIT;
+    rect.width = i->GetWidth();
+    //rect.height = i->GetHeight();
+    rect.height = GetLineHeight(i);
+
+    return TRUE;
 }
 
 /* **** */
 }
 
 /* **** */
@@ -2118,7 +2329,7 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
     m_currentEdit = (wxGenericTreeItem*) item.m_pItem;
 
     wxTreeEvent te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, GetId() );
     m_currentEdit = (wxGenericTreeItem*) item.m_pItem;
 
     wxTreeEvent te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, GetId() );
-    te.m_item = m_currentEdit;
+    te.m_item = (long) m_currentEdit;
     te.SetEventObject( this );
     GetEventHandler()->ProcessEvent( te );
 
     te.SetEventObject( this );
     GetEventHandler()->ProcessEvent( te );
 
@@ -2127,7 +2338,7 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
     // We have to call this here because the label in
     // question might just have been added and no screen
     // update taken place.
     // 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();
+    if (m_dirty) wxYieldIfNeeded();
 
     wxString s = m_currentEdit->GetText();
     int x = m_currentEdit->GetX();
 
     wxString s = m_currentEdit->GetText();
     int x = m_currentEdit->GetX();
@@ -2159,8 +2370,13 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item )
     x = dc.LogicalToDeviceX( x );
     y = dc.LogicalToDeviceY( y );
 
     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) );
+    wxTreeTextCtrl *text = new wxTreeTextCtrl(this, -1,
+                                              &m_renameAccept,
+                                              &m_renameRes,
+                                              this,
+                                              s,
+                                              wxPoint(x-4,y-4),
+                                              wxSize(w+11,h+8));
     text->SetFocus();
 }
 
     text->SetFocus();
 }
 
@@ -2172,7 +2388,7 @@ void wxGenericTreeCtrl::OnRenameTimer()
 void wxGenericTreeCtrl::OnRenameAccept()
 {
     wxTreeEvent le( wxEVT_COMMAND_TREE_END_LABEL_EDIT, GetId() );
 void wxGenericTreeCtrl::OnRenameAccept()
 {
     wxTreeEvent le( wxEVT_COMMAND_TREE_END_LABEL_EDIT, GetId() );
-    le.m_item = m_currentEdit;
+    le.m_item = (long) m_currentEdit;
     le.SetEventObject( this );
     le.m_label = m_renameRes;
     GetEventHandler()->ProcessEvent( le );
     le.SetEventObject( this );
     le.m_label = m_renameRes;
     GetEventHandler()->ProcessEvent( le );
@@ -2227,7 +2443,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
                               : wxEVT_COMMAND_TREE_BEGIN_DRAG;
 
         wxTreeEvent nevent( command, GetId() );
                               : wxEVT_COMMAND_TREE_BEGIN_DRAG;
 
         wxTreeEvent nevent( command, GetId() );
-        nevent.m_item = m_current;
+        nevent.m_item = (long) m_current;
         nevent.SetEventObject(this);
 
         // by default the dragging is not supported, the user code must
         nevent.SetEventObject(this);
 
         // by default the dragging is not supported, the user code must
@@ -2270,7 +2486,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
             // highlight the current drop target if any
             DrawDropEffect(m_dropTarget);
 
             // highlight the current drop target if any
             DrawDropEffect(m_dropTarget);
 
-            wxYield();
+            wxYieldIfNeeded();
         }
     }
     else if ( (event.LeftUp() || event.RightUp()) && m_isDragging )
         }
     }
     else if ( (event.LeftUp() || event.RightUp()) && m_isDragging )
@@ -2281,7 +2497,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
         // generate the drag end event
         wxTreeEvent event(wxEVT_COMMAND_TREE_END_DRAG, GetId());
 
         // generate the drag end event
         wxTreeEvent event(wxEVT_COMMAND_TREE_END_DRAG, GetId());
 
-        event.m_item = item;
+        event.m_item = (long) item;
         event.m_pointDrag = wxPoint(x, y);
         event.SetEventObject(this);
 
         event.m_pointDrag = wxPoint(x, y);
         event.SetEventObject(this);
 
@@ -2301,7 +2517,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
 
         SetCursor(m_oldCursor);
 
 
         SetCursor(m_oldCursor);
 
-        wxYield();
+        wxYieldIfNeeded();
     }
     else
     {
     }
     else
     {
@@ -2314,29 +2530,51 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
         if ( event.RightDown() )
         {
             wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, GetId());
         if ( event.RightDown() )
         {
             wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, GetId());
-            nevent.m_item = item;
+            nevent.m_item = (long) item;
             nevent.m_code = 0;
             nevent.m_code = 0;
+            CalcScrolledPosition(x, y,
+                                 &nevent.m_pointDrag.x,
+                                 &nevent.m_pointDrag.y);
             nevent.SetEventObject(this);
             GetEventHandler()->ProcessEvent(nevent);
         }
             nevent.SetEventObject(this);
             GetEventHandler()->ProcessEvent(nevent);
         }
-        else if ( event.LeftUp() && m_lastOnSame )
+        else if ( event.LeftUp() )
         {
         {
-            if ( (item == m_current) &&
-                 (flags & wxTREE_HITTEST_ONITEMLABEL) &&
-                 HasFlag(wxTR_EDIT_LABELS) )
+            if ( m_lastOnSame )
             {
             {
-                m_renameTimer->Start( 100, TRUE );
-            }
+                if ( (item == m_current) &&
+                     (flags & wxTREE_HITTEST_ONITEMLABEL) &&
+                     HasFlag(wxTR_EDIT_LABELS) )
+                {
+                    if ( m_renameTimer->IsRunning() )
+                        m_renameTimer->Stop();
+
+                    m_renameTimer->Start( 100, TRUE );
+                }
 
 
-            m_lastOnSame = FALSE;
+                m_lastOnSame = FALSE;
+            }
         }
         }
-        else
+        else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick()
         {
             if ( event.LeftDown() )
             {
                 m_lastOnSame = item == m_current;
             }
 
         {
             if ( event.LeftDown() )
             {
                 m_lastOnSame = item == m_current;
             }
 
+            if ( flags & wxTREE_HITTEST_ONITEMBUTTON )
+            {
+                // only toggle the item for a single click, double click on
+                // the button doesn't do anything (it toggles the item twice)
+                if ( event.LeftDown() )
+                {
+                    Toggle( item );
+                }
+
+                // don't select the item if the button was clicked
+                return;
+            }
+
             // how should the selection work for this event?
             bool is_multiple, extended_select, unselect_others;
             EventFlagsToSelType(GetWindowStyleFlag(),
             // how should the selection work for this event?
             bool is_multiple, extended_select, unselect_others;
             EventFlagsToSelType(GetWindowStyleFlag(),
@@ -2344,13 +2582,6 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
                                 event.ControlDown(),
                                 is_multiple, extended_select, unselect_others);
 
                                 event.ControlDown(),
                                 is_multiple, extended_select, unselect_others);
 
-            if ( (flags & wxTREE_HITTEST_ONITEMBUTTON) && event.LeftDown() )
-            {
-                Toggle( item );
-                if ( is_multiple )
-                    return;
-            }
-
             SelectItem(item, unselect_others, extended_select);
 
             if ( event.LeftDClick() )
             SelectItem(item, unselect_others, extended_select);
 
             if ( event.LeftDClick() )
@@ -2360,8 +2591,11 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
                 m_lastOnSame = FALSE;
 
                 wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
                 m_lastOnSame = FALSE;
 
                 wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() );
-                nevent.m_item = item;
+                nevent.m_item = (long) item;
                 nevent.m_code = 0;
                 nevent.m_code = 0;
+                CalcScrolledPosition(x, y,
+                                     &nevent.m_pointDrag.x,
+                                     &nevent.m_pointDrag.y);
                 nevent.SetEventObject( this );
                 GetEventHandler()->ProcessEvent( nevent );
             }
                 nevent.SetEventObject( this );
                 GetEventHandler()->ProcessEvent( nevent );
             }
@@ -2509,3 +2743,4 @@ void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem *item )
     Refresh( TRUE, &rect );
 }
 
     Refresh( TRUE, &rect );
 }
 
+#endif // wxUSE_TREECTRL