Remove const bool
[wxWidgets.git] / wxPython / wx / lib / customtreectrl.py
index 87313192a2a68e99c36392ed7f3ca0799b7d2f6a..a33b8574ce7e6c22ae45afab45ad1cc63e6317a2 100644 (file)
@@ -3,7 +3,7 @@
 # Inspired By And Heavily Based On wxGenericTreeCtrl.
 #
 # Andrea Gavana, @ 17 May 2006
-# Latest Revision: 26 May 2006, 22.30 CET
+# Latest Revision: 16 Apr 2007, 11.00 CET
 #
 #
 # TODO List
@@ -134,8 +134,8 @@ CustomTreeCtrl has been tested on the following platforms:
   * Mac OS (Thanks to John Jackson).
 
 
-Latest Revision: Andrea Gavana @ 26 May 2006, 22.30 CET
-Version 0.8
+Latest Revision: Andrea Gavana @ 16 Apr 2007, 11.00 CET
+Version 1.0
 
 """
 
@@ -1164,28 +1164,7 @@ class GenericTreeItem:
         self._wnd = wnd             # are we holding a window?
 
         if wnd:
-            if wnd.GetSizer():      # the window is a complex one hold by a sizer
-                size = wnd.GetBestSize()
-            else:                   # simple window, without sizers
-                size = wnd.GetSize()
-
-            # We have to bind the wx.EVT_SET_FOCUS for the associated window
-            # No other solution to handle the focus changing from an item in
-            # CustomTreeCtrl and the window associated to an item
-            # Do better strategies exist?
-            self._wnd.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
-            
-            self._height = size.GetHeight() + 2
-            self._width = size.GetWidth()
-            self._windowsize = size
-            
-            # We don't show the window if the item is collapsed
-            if self._isCollapsed:
-                self._wnd.Show(False)
-
-            # The window is enabled only if the item is enabled                
-            self._wnd.Enable(self._enabled)
-            self._windowenabled = self._enabled
+            self.SetWindow(wnd)
         
 
     def IsOk(self):
@@ -1310,6 +1289,29 @@ class GenericTreeItem:
 
         self._wnd = wnd
 
+        if wnd.GetSizer():      # the window is a complex one hold by a sizer
+            size = wnd.GetBestSize()
+        else:                   # simple window, without sizers
+            size = wnd.GetSize()
+
+        # We have to bind the wx.EVT_SET_FOCUS for the associated window
+        # No other solution to handle the focus changing from an item in
+        # CustomTreeCtrl and the window associated to an item
+        # Do better strategies exist?
+        self._wnd.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
+        
+        self._height = size.GetHeight() + 2
+        self._width = size.GetWidth()
+        self._windowsize = size
+        
+        # We don't show the window if the item is collapsed
+        if self._isCollapsed:
+            self._wnd.Show(False)
+
+        # The window is enabled only if the item is enabled                
+        self._wnd.Enable(self._enabled)
+        self._windowenabled = self._enabled
+
 
     def GetWindow(self):
         """Returns the window associated to the item."""
@@ -1317,6 +1319,14 @@ class GenericTreeItem:
         return self._wnd        
 
 
+    def DeleteWindow(self):
+        """Deletes the window associated to the item (if any)."""
+
+        if self._wnd:
+            self._wnd.Destroy()
+            self._wnd = None
+        
+
     def GetWindowEnabled(self):
         """Returns whether the associated window is enabled or not."""
 
@@ -1736,7 +1746,7 @@ def EventFlagsToSelType(style, shiftDown=False, ctrlDown=False):
 class CustomTreeCtrl(wx.PyScrolledWindow):
 
     def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize,
-                 style=0, ctstyle=TR_DEFAULT_STYLE, validator=wx.DefaultValidator,
+                 style=TR_DEFAULT_STYLE, ctstyle=0, validator=wx.DefaultValidator,
                  name="CustomTreeCtrl"):
         """
         Default class constructor.
@@ -1749,15 +1759,14 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
 
         size: window size. If the default size (-1, -1) is specified then the window is sized appropriately.
 
-        style: the underlying wx.ScrolledWindow style
+        style: the underlying wx.ScrolledWindow style + CustomTreeCtrl window style. This can be one of:
         
-        ctstyle: CustomTreeCtrl window style. This can be one of:
             TR_NO_BUTTONS
             TR_HAS_BUTTONS                          # draw collapsed/expanded btns
             TR_NO_LINES                             # don't draw lines at all
             TR_LINES_AT_ROOT                        # connect top-level nodes
             TR_TWIST_BUTTONS                        # draw mac-like twist buttons
-            TR_SINGLE                               # single selection mode                           
+            TR_SINGLE                               # single selection mode     
             TR_MULTIPLE                             # can select multiple items
             TR_EXTENDED                             # todo: allow extended selection
             TR_HAS_VARIABLE_ROW_HEIGHT              # allows rows to have variable height
@@ -1769,10 +1778,14 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             TR_AUTO_CHECK_PARENT                    # only meaningful for checkboxes
             TR_AUTO_TOGGLE_CHILD                    # only meaningful for checkboxes
 
+        ctstyle: kept for backward compatibility.
+        
         validator: window validator.
 
         name: window name.
         """
+
+        style = style | ctstyle
         
         self._current = self._key_current = self._anchor = self._select_me = None
         self._hasFocus = False
@@ -1857,12 +1870,13 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         self._vistaselection = False        
 
         # Connection lines style
+        grey = (160,160,160)
         if wx.Platform != "__WXMAC__":
-            self._dottedPen = wx.Pen("grey", 1, wx.USER_DASH)
+            self._dottedPen = wx.Pen(grey, 1, wx.USER_DASH)
             self._dottedPen.SetDashes([1,1])
             self._dottedPen.SetCap(wx.CAP_BUTT)
         else:
-            self._dottedPen = wx.Pen("grey", 1)
+            self._dottedPen = wx.Pen(grey, 1)
 
         # Pen Used To Draw The Border Around Selected Items
         self._borderPen = wx.BLACK_PEN
@@ -1873,14 +1887,12 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         self._itemWithWindow = []
         
         if wx.Platform == "__WXMAC__":
-            ctstyle &= ~TR_LINES_AT_ROOT
-            ctstyle |= TR_NO_LINES
+            style &= ~TR_LINES_AT_ROOT
+            style |= TR_NO_LINES
             
             platform, major, minor = wx.GetOsVersion()
             if major < 10:
-                ctstyle |= TR_ROW_LINES
-
-        self._windowStyle = ctstyle
+                style |= TR_ROW_LINES
 
         # Create the default check image list        
         self.SetImageListCheck(13, 13)
@@ -2052,7 +2064,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             self.RefreshLine(item)
                 
 
-    def IsEnabled(self, item):
+    def IsItemEnabled(self, item):
         """Returns whether an item is enabled or disabled."""
 
         if not item:
@@ -2156,13 +2168,13 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         dc = wx.ClientDC(self)
         self.RefreshLine(item)
 
-        if self._windowStyle & TR_AUTO_CHECK_CHILD:
+        if self.HasFlag(TR_AUTO_CHECK_CHILD):
             ischeck = self.IsItemChecked(item)
             self.AutoCheckChild(item, ischeck)
-        if self._windowStyle & TR_AUTO_CHECK_PARENT:
+        if self.HasFlag(TR_AUTO_CHECK_PARENT):
             ischeck = self.IsItemChecked(item)
             self.AutoCheckParent(item, ischeck)
-        elif self._windowStyle & TR_AUTO_TOGGLE_CHILD:
+        elif self.HasFlag(TR_AUTO_TOGGLE_CHILD):
             self.AutoToggleChild(item)
 
         e = TreeEvent(wxEVT_TREE_ITEM_CHECKED, self.GetId())
@@ -2297,12 +2309,6 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         self._dirty = True
 
 
-    def HasFlag(self, flag):
-        """Returns whether CustomTreeCtrl has a flag."""
-
-        return self._windowStyle & flag
-    
-
     def HasChildren(self, item):
         """Returns whether an item has children or not."""
 
@@ -2336,19 +2342,19 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         # want to update the inherited styles, but right now
         # none of the parents has updatable styles
 
-        if self._windowStyle & TR_MULTIPLE and not (styles & TR_MULTIPLE):
+        if self.HasFlag(TR_MULTIPLE) and not (styles & TR_MULTIPLE):
             selections = self.GetSelections()
             for select in selections[0:-1]:
                 self.SelectItem(select, False)
 
-        self._windowStyle = styles
+        self.SetWindowStyle(styles)
         self._dirty = True
 
 
     def GetTreeStyle(self):
         """Returns the CustomTreeCtrl style."""
 
-        return self._windowStyle
+        return self.GetWindowStyle()
     
 
     def HasButtons(self):
@@ -2370,7 +2376,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         return item.GetText()
     
 
-    def GetItemImage(self, item, which):
+    def GetItemImage(self, item, which=TreeItemIcon_Normal):
         """Returns the item image."""
 
         if not item:
@@ -3142,10 +3148,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
     def DoInsertItem(self, parentId, previous, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
         """Actually inserts an item in the tree."""
 
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
         if ct_type < 0 or ct_type > 2:
@@ -3177,10 +3183,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         if self._anchor:
             raise Exception("\nERROR: Tree Can Have Only One Root")
 
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
         if ct_type < 0 or ct_type > 2:
@@ -3213,10 +3219,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
     def PrependItem(self, parent, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
         """Appends an item as a first child of parent."""
 
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
         
         return self.DoInsertItem(parent, 0, text, ct_type, wnd, image, selImage, data)
@@ -3225,10 +3231,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
     def InsertItemByItem(self, parentId, idPrevious, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
         """Auxiliary function to cope with the C++ hideous multifunction."""
         
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
         
         parent = parentId
@@ -3251,10 +3257,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
     def InsertItemByIndex(self, parentId, before, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
         """Auxiliary function to cope with the C++ hideous multifunction."""
 
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
         
         parent = parentId
@@ -3269,10 +3275,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
     def InsertItem(self, parentId, input, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
         """Inserts an item after the given previous."""
 
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
         
         if type(input) == type(1):
@@ -3284,10 +3290,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
     def AppendItem(self, parentId, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None):
         """Appends an item as a last child of its parent."""
 
-        if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if wnd is not None and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
 
-        if text.find("\n") >= 0 and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
+        if text.find("\n") >= 0 and not self.HasFlag(TR_HAS_VARIABLE_ROW_HEIGHT):
             raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT")
         
         parent = parentId
@@ -3305,7 +3311,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         event = TreeEvent(wxEVT_TREE_DELETE_ITEM, self.GetId())
         event._item = item
         event.SetEventObject(self)
-        self.ProcessEvent(event)
+        self.GetEventHandler().ProcessEvent(event)
 
 
     def IsDescendantOf(self, parent, item):
@@ -3450,7 +3456,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         event._item = item
         event.SetEventObject(self)
 
-        if self.ProcessEvent(event) and not event.IsAllowed():
+        if self.GetEventHandler().ProcessEvent(event) and not event.IsAllowed():
             # cancelled by program
             return
     
@@ -3464,11 +3470,11 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             self.HideWindows()
             
         event.SetEventType(wxEVT_TREE_ITEM_EXPANDED)
-        self.ProcessEvent(event)
+        self.GetEventHandler().ProcessEvent(event)
 
 
-    def ExpandAll(self, item):
-        """Expands all the items."""
+    def ExpandAllChildren(self, item):
+        """Expands all the items children of the input item."""
 
         if not item:
             raise Exception("\nERROR: Invalid Tree Item. ")
@@ -3481,10 +3487,17 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         child, cookie = self.GetFirstChild(item)
         
         while child:
-            self.ExpandAll(child)
+            self.ExpandAllChildren(child)
             child, cookie = self.GetNextChild(item, cookie)
         
 
+    def ExpandAll(self):
+        """Expands all CustomTreeCtrl items."""
+
+        if self._anchor:
+            self.ExpandAllChildren(self._anchor)
+            
+
     def Collapse(self, item):
         """
         Collapse an item, sending a EVT_TREE_ITEM_COLLAPSING and
@@ -3503,7 +3516,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         event = TreeEvent(wxEVT_TREE_ITEM_COLLAPSING, self.GetId())
         event._item = item
         event.SetEventObject(self)
-        if self.ProcessEvent(event) and not event.IsAllowed():
+        if self.GetEventHandler().ProcessEvent(event) and not event.IsAllowed():
             # cancelled by program
             return
     
@@ -3517,7 +3530,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             self.HideWindows()
             
         event.SetEventType(wxEVT_TREE_ITEM_COLLAPSED)
-        self.ProcessEvent(event)
+        self.GetEventHandler().ProcessEvent(event)
 
 
     def CollapseAndReset(self, item):
@@ -3542,7 +3555,8 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         for child in self._itemWithWindow:
             if not self.IsVisible(child):
                 wnd = child.GetWindow()
-                wnd.Hide()
+                if wnd:
+                    wnd.Hide()
             
 
     def Unselect(self):
@@ -3578,7 +3592,8 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         # the tree might not have the root item at all
         if rootItem:
             self.UnselectAllChildren(rootItem)
-        
+
+        self.Unselect()        
 
     # Recursive function !
     # To stop we must have crt_item<last_item
@@ -3958,21 +3973,22 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         self._imageListNormal = imageList
         self._ownsImageListNormal = False
         self._dirty = True
+        
         # Don't do any drawing if we're setting the list to NULL,
         # since we may be in the process of deleting the tree control.
         if imageList:
             self.CalculateLineHeight()
 
-        # We gray out the image list to use the grayed icons with disabled items
-        self._grayedImageList = wx.ImageList(16, 16, True, 0)
-        
-        for ii in xrange(imageList.GetImageCount()):
-            
-            bmp = imageList.GetBitmap(ii)
-            image = wx.ImageFromBitmap(bmp)
-            image = GrayOut(image)
-            newbmp = wx.BitmapFromImage(image)
-            self._grayedImageList.Add(newbmp)
+            # We gray out the image list to use the grayed icons with disabled items
+            sz = imageList.GetSize(0)
+            self._grayedImageList = wx.ImageList(sz[0], sz[1], True, 0)
+
+            for ii in xrange(imageList.GetImageCount()):
+                bmp = imageList.GetBitmap(ii)
+                image = wx.ImageFromBitmap(bmp)
+                image = GrayOut(image)
+                newbmp = wx.BitmapFromImage(image)
+                self._grayedImageList.Add(newbmp)
         
 
     def SetStateImageList(self, imageList):
@@ -4190,6 +4206,8 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         r2, g2, b2 = int(bottom.Red()), int(bottom.Green()), int(bottom.Blue())
 
         flrect = float(filRect.height)
+        if flrect < 1:
+            flrect = self._lineHeight
 
         rstep = float((r2 - r1)) / flrect
         gstep = float((g2 - g1)) / flrect
@@ -4232,7 +4250,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                 dc.SetTextForeground(self.GetHyperTextVisitedColour())
             else:
                 dc.SetTextForeground(self.GetHyperTextNewColour())
-
+                    
         text_w, text_h, dummy = dc.GetMultiLineTextExtent(item.GetText())
 
         image = item.GetCurrentImage()
@@ -4304,7 +4322,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                         wx.RendererNative.Get().DrawItemSelectionRect(self, dc, itemrect, flags) 
                     else:
                         dc.DrawRectangleRect(itemrect)
-
+                
         else:
 
             if item.IsSelected():
@@ -4402,6 +4420,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         if wnd:
             wndx = wcheck + image_w + item.GetX() + text_w + 4
             xa, ya = self.CalcScrolledPosition((0, item.GetY()))
+            wndx += xa
+            if item.GetHeight() > item.GetWindowSize()[1]:
+                ya += (item.GetHeight() - item.GetWindowSize()[1])/2
+                
             if not wnd.IsShown():
                 wnd.Show()
             if wnd.GetPosition() != (wndx, ya):
@@ -4440,7 +4462,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                     # draw line down to last child
                     origY += self.GetLineHeight(children[0])>>1
                     oldY += self.GetLineHeight(children[n-1])>>1
+                    oldPen = dc.GetPen()
+                    dc.SetPen(self._dottedPen)
                     dc.DrawLine(3, origY, 3, oldY)
+                    dc.SetPen(oldPen)
                 
             return y
         
@@ -4534,7 +4559,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                     
                 else: # no custom buttons
 
-                    if self._windowStyle & TR_TWIST_BUTTONS:
+                    if self.HasFlag(TR_TWIST_BUTTONS):
                         # We draw something like the Mac twist buttons
                         
                         dc.SetPen(wx.BLACK_PEN)
@@ -4726,11 +4751,11 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         keyCode = event.GetKeyCode()
 
         if keyCode in [ord("+"), wx.WXK_ADD]:       # "+"
-            if self._current.HasPlus() and not self.IsExpanded(self._current) and self.IsEnabled(self._current):
+            if self._current.HasPlus() and not self.IsExpanded(self._current) and self.IsItemEnabled(self._current):
                 self.Expand(self._current)
                 
         elif keyCode in [ord("*"), wx.WXK_MULTIPLY]:  # "*"
-            if not self.IsExpanded(self._current) and self.IsEnabled(self._current):
+            if not self.IsExpanded(self._current) and self.IsItemEnabled(self._current):
                 # expand all
                 self.ExpandAll(self._current)
 
@@ -4750,7 +4775,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                 
         elif keyCode in [wx.WXK_RETURN, wx.WXK_SPACE]:
 
-            if not self.IsEnabled(self._current):
+            if not self.IsItemEnabled(self._current):
                 event.Skip()
                 return
             
@@ -4783,7 +4808,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                 if prev:
                     current = self._key_current
                     # TODO: Huh?  If we get here, we'd better be the first child of our parent.  How else could it be?
-                    if current == self.GetFirstChild(prev)[0] and self.IsEnabled(prev):
+                    if current == self.GetFirstChild(prev)[0] and self.IsItemEnabled(prev):
                         # otherwise we return to where we came from
                         self.DoSelectItem(prev, unselect_others, extended_select)
                         self._key_current = prev
@@ -4799,13 +4824,13 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                         current = prev
                 
                 # Try to get the previous siblings and see if they are active
-                while prev and not self.IsEnabled(prev):
+                while prev and not self.IsItemEnabled(prev):
                     prev = self.GetPrevSibling(prev)
 
                 if not prev:
                     # No previous siblings active: go to the parent and up
                     prev = self.GetItemParent(current)
-                    while prev and not self.IsEnabled(prev):
+                    while prev and not self.IsItemEnabled(prev):
                         prev = self.GetItemParent(prev)
                         
                 if prev:
@@ -4823,7 +4848,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             if self.IsExpanded(self._current):
                 self.Collapse(self._current)
             else:
-                if prev and self.IsEnabled(prev):
+                if prev and self.IsItemEnabled(prev):
                     self.DoSelectItem(prev, unselect_others, extended_select)
                 
         elif keyCode == wx.WXK_RIGHT:
@@ -4831,7 +4856,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             # also expand the item if it wasn't expanded yet
             if self.IsExpanded(self._current) and self.HasChildren(self._current):
                 child, cookie = self.GetFirstChild(self._key_current)
-                if self.IsEnabled(child):
+                if self.IsItemEnabled(child):
                     self.DoSelectItem(child, unselect_others, extended_select)
                     self._key_current = child
             else:
@@ -4857,11 +4882,11 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                         current = self.GetItemParent(current)
                         if current:
                             next = self.GetNextSibling(current)
-                            if not next or not self.IsEnabled(next):
+                            if not next or not self.IsItemEnabled(next):
                                 next = None
 
                 else:
-                    while next and not self.IsEnabled(next):
+                    while next and not self.IsItemEnabled(next):
                         next = self.GetNext(next)
                     
                 if next:
@@ -4886,7 +4911,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
 
                 last = lastChild
             
-            if last and self.IsEnabled(last):
+            if last and self.IsItemEnabled(last):
             
                 self.DoSelectItem(last, unselect_others, extended_select)
                 
@@ -4903,7 +4928,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                 if not prev:
                     return
 
-            if self.IsEnabled(prev):
+            if self.IsItemEnabled(prev):
                 self.DoSelectItem(prev, unselect_others, extended_select)
         
         else:
@@ -4920,7 +4945,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                     # no such item
                     return
 
-                if self.IsEnabled(id):                
+                if self.IsItemEnabled(id):                
                     self.SelectItem(id)
                 self._findPrefix += ch
 
@@ -4952,7 +4977,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
 
             while 1:
                 child = sibling(item)
-                if (child and self.IsEnabled(child)) or not child:
+                if (child and self.IsItemEnabled(child)) or not child:
                     break
                 item = child
 
@@ -4960,10 +4985,10 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             # Tha's not a radiobutton... but some of its children can be
             # inactive
             child, cookie = self.GetFirstChild(item)
-            while child and not self.IsEnabled(child):
+            while child and not self.IsItemEnabled(child):
                 child, cookie = self.GetNextChild(item, cookie)
                 
-        if child and self.IsEnabled(child):
+        if child and self.IsItemEnabled(child):
             return child
             
         return None
@@ -5017,7 +5042,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             flags = TREE_HITTEST_NOWHERE
             return None, flags
 
-        if not self.IsEnabled(hit):
+        if not self.IsItemEnabled(hit):
             return None, flags
 
         return hit, flags
@@ -5536,6 +5561,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             item.SetHeight(total_h)
         else:
             item.SetWidth(item.GetWindowSize()[0]+image_w+text_w+wcheck+2)
+            item.SetHeight(max(total_h, item.GetWindowSize()[1]))
 
 
     def CalculateLevel(self, item, dc, level, y):
@@ -5733,4 +5759,6 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         attr.font  = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
         return attr
 
+    GetClassDefaultAttributes = classmethod(GetClassDefaultAttributes)
 
+