]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/lib/customtreectrl.py
don't use TPM_RECURSE under NT4, it results in TrackPopupMenu() not showing the menu...
[wxWidgets.git] / wxPython / wx / lib / customtreectrl.py
index 1616f48adbcf55f63e7bb6e0a7f07729a9b7eaea..87313192a2a68e99c36392ed7f3ca0799b7d2f6a 100644 (file)
@@ -95,8 +95,9 @@ Base Functionalities
 CustomTreeCtrl supports all the wx.TreeCtrl styles, except:
   - TR_EXTENDED: supports for this style is on the todo list (Am I sure of this?).
 
-Plus it has 2 more styles to handle checkbox-type items:
+Plus it has 3 more styles to handle checkbox-type items:
   - TR_AUTO_CHECK_CHILD : automatically checks/unchecks the item children;
+  - TR_AUTO_CHECK_PARENT : automatically checks/unchecks the item parent;
   - TR_AUTO_TOGGLE_CHILD: automatically toggles the item children.
 
 All the methods available in wx.TreeCtrl are also available in CustomTreeCtrl.
@@ -190,8 +191,9 @@ TR_HIDE_ROOT = wx.TR_HIDE_ROOT                                 # don't display r
 
 TR_FULL_ROW_HIGHLIGHT = wx.TR_FULL_ROW_HIGHLIGHT               # highlight full horz space
 
-TR_AUTO_CHECK_CHILD = 0x4000                                   # only meaningful for checkboxes
-TR_AUTO_TOGGLE_CHILD = 0x8000                                  # only meaningful for checkboxes
+TR_AUTO_CHECK_CHILD = 0x04000                                   # only meaningful for checkboxes
+TR_AUTO_TOGGLE_CHILD = 0x08000                                  # only meaningful for checkboxes
+TR_AUTO_CHECK_PARENT = 0x10000                                   # only meaningful for checkboxes
 
 TR_DEFAULT_STYLE = wx.TR_DEFAULT_STYLE                         # default style for the tree control
 
@@ -492,9 +494,9 @@ class DragImage(wx.DragImage):
         text = item.GetText()
         font = item.Attr().GetFont()
         colour = item.Attr().GetTextColour()
-        if colour is None:
+        if not colour:
             colour = wx.BLACK
-        if font is None:
+        if not font:
             font = treeCtrl._normalFont
     
         backcolour = treeCtrl.GetBackgroundColour()
@@ -922,7 +924,7 @@ class TreeTextCtrl(wx.TextCtrl):
         
             else:
         
-                raise "\n ERROR: You Must Create An Image List To Use Images!"
+                raise Exception("\n ERROR: You Must Create An Image List To Use Images!")
 
         checkimage = item.GetCurrentCheckedImage()
 
@@ -942,16 +944,12 @@ class TreeTextCtrl(wx.TextCtrl):
         x += image_w + wcheck
         w -= image_w + 4 + wcheck
 
-        if wx.Platform == "__WXMAC__":
-            bs = self.DoGetBestSize() 
-            # edit control height
-            if h > bs.y - 8:
-                diff = h - ( bs.y - 8 ) 
-                h -= diff 
-                y += diff / 2 
-
         wx.TextCtrl.__init__(self, self._owner, wx.ID_ANY, self._startValue,
                              wx.Point(x - 4, y), wx.Size(w + 15, h))
+        if wx.Platform == "__WXMAC__":
+            self.SetFont(owner.GetFont())
+            bs = self.GetBestSize()
+            self.SetSize((-1, bs.height))
         
         self.Bind(wx.EVT_CHAR, self.OnChar)
         self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
@@ -1323,7 +1321,7 @@ class GenericTreeItem:
         """Returns whether the associated window is enabled or not."""
 
         if not self._wnd:
-            raise "\nERROR: This Item Has No Window Associated"
+            raise Exception("\nERROR: This Item Has No Window Associated")
 
         return self._windowenabled
 
@@ -1332,7 +1330,7 @@ class GenericTreeItem:
         """Sets whether the associated window is enabled or not."""
 
         if not self._wnd:
-            raise "\nERROR: This Item Has No Window Associated"
+            raise Exception("\nERROR: This Item Has No Window Associated")
 
         self._windowenabled = enable
         self._wnd.Enable(enable)
@@ -1735,7 +1733,7 @@ def EventFlagsToSelType(style, shiftDown=False, ctrlDown=False):
 # This Is The Main Class.
 # -----------------------------------------------------------------------------
 
-class CustomTreeCtrl(wx.ScrolledWindow):
+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,
@@ -1768,6 +1766,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             TR_HIDE_ROOT                            # don't display root node
             TR_FULL_ROW_HIGHLIGHT                   # highlight full horizontal space
             TR_AUTO_CHECK_CHILD                     # only meaningful for checkboxes
+            TR_AUTO_CHECK_PARENT                    # only meaningful for checkboxes
             TR_AUTO_TOGGLE_CHILD                    # only meaningful for checkboxes
 
         validator: window validator.
@@ -1791,7 +1790,9 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         btnshadow = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW)
         self._hilightUnfocusedBrush = wx.Brush(btnshadow)
         r, g, b = btnshadow.Red(), btnshadow.Green(), btnshadow.Blue()
-        backcolour = ((r >> 1) - 20, (g >> 1) - 20, (b >> 1) - 20)
+        backcolour = (max((r >> 1) - 20, 0),
+                      max((g >> 1) - 20, 0),
+                      max((b >> 1) - 20, 0))
         backcolour = wx.Colour(backcolour[0], backcolour[1], backcolour[2])
         self._hilightUnfocusedBrush2 = wx.Brush(backcolour)
 
@@ -1872,12 +1873,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         self._itemWithWindow = []
         
         if wx.Platform == "__WXMAC__":
-            
-            platform, major, minor = wx.GetOsVersion()
-
             ctstyle &= ~TR_LINES_AT_ROOT
             ctstyle |= TR_NO_LINES
             
+            platform, major, minor = wx.GetOsVersion()
             if major < 10:
                 ctstyle |= TR_ROW_LINES
 
@@ -1894,7 +1893,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             self._drawingfunction = wx.RendererNative.Get().DrawTreeItemButton
 
         # Create our container... at last!    
-        wx.ScrolledWindow.__init__(self, parent, id, pos, size, style|wx.HSCROLL|wx.VSCROLL, name)
+        wx.PyScrolledWindow.__init__(self, parent, id, pos, size, style|wx.HSCROLL|wx.VSCROLL, name)
 
         # If the tree display has no buttons, but does have
         # connecting lines, we can use a narrower layout.
@@ -1922,15 +1921,19 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
         self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
         self.Bind(EVT_TREE_ITEM_GETTOOLTIP, self.OnGetToolTip)
-        self.Bind(wx.EVT_IDLE, self.OnInternalIdle)
         self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
 
         # Sets the focus to ourselves: this is useful if you have items
         # with associated widgets.
         self.SetFocus()
 
-        return True
 
+    def AcceptsFocus(self):
+        # overridden base class method, allows this ctrl to
+        # participate in the tab-order, etc.  It's overridable because
+        # of deriving this class from wx.PyScrolledWindow...
+        return True
+    
 
     def OnDestroy(self, event):
         """Handles the wx.EVT_WINDOW_DESTROY event."""
@@ -1992,7 +1995,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Toggles the item selection."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         self.SelectItem(item, not self.IsSelected(item))
 
@@ -2022,7 +2025,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Enables/disables an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         if item.IsEnabled() == enable:
             return
@@ -2053,7 +2056,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether an item is enabled or disabled."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         return item.IsEnabled()        
 
@@ -2075,7 +2078,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether an item is checked or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "        
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.IsChecked()
 
@@ -2105,7 +2108,6 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             return False
 
         item.Check(checked)
-        dc = wx.ClientDC(self)
         self.RefreshLine(item)
         self.EnableChildren(item, checked)
         e = TreeEvent(wxEVT_TREE_ITEM_CHECKED, self.GetId())
@@ -2123,7 +2125,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         # Should we raise an error here?!?        
         if item.GetType() == 0:
@@ -2157,6 +2159,9 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         if self._windowStyle & TR_AUTO_CHECK_CHILD:
             ischeck = self.IsItemChecked(item)
             self.AutoCheckChild(item, ischeck)
+        if self._windowStyle & TR_AUTO_CHECK_PARENT:
+            ischeck = self.IsItemChecked(item)
+            self.AutoCheckParent(item, ischeck)
         elif self._windowStyle & TR_AUTO_TOGGLE_CHILD:
             self.AutoToggleChild(item)
 
@@ -2170,7 +2175,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Transverses the tree and toggles the items. Meaningful only for check items."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         child, cookie = self.GetFirstChild(item)
 
@@ -2190,7 +2195,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Transverses the tree and checks/unchecks the items. Meaningful only for check items."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         (child, cookie) = self.GetFirstChild(item)
 
@@ -2205,11 +2210,33 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             (child, cookie) = self.GetNextChild(item, cookie)
 
 
+    def AutoCheckParent(self, item, checked):
+        """Traverses up the tree and checks/unchecks parent items.
+        Meaningful only for check items."""
+
+        if not item:
+            raise Exception("\nERROR: Invalid Tree Item. ")
+
+        parent = item.GetParent()
+        if not parent or parent.GetType() != 1:
+            return
+
+        (child, cookie) = self.GetFirstChild(parent)
+        while child:
+            if child.GetType() == 1 and child.IsEnabled():
+                if checked != child.IsChecked():
+                    return
+            (child, cookie) = self.GetNextChild(parent, cookie)
+
+        self.CheckItem2(parent, checked, torefresh=True)
+        self.AutoCheckParent(parent, checked)
+
+
     def CheckChilds(self, item, checked=True):
         """Programatically check/uncheck item children. Does not generate EVT_TREE_CHECK* events."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         if checked == None:
             self.AutoToggleChild(item)
@@ -2245,7 +2272,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Starts editing an item label."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         self.Edit(item)
 
@@ -2280,7 +2307,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether an item has children or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         return len(item.GetChildren()) > 0
 
@@ -2289,7 +2316,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the item children count."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetChildrenCount(recursively)
 
@@ -2338,7 +2365,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the item text."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetText()
     
@@ -2347,7 +2374,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the item image."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetImage(which)
 
@@ -2356,7 +2383,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the data associated to an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetData()
 
@@ -2367,7 +2394,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the item text colour."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.Attr().GetTextColour()
 
@@ -2376,7 +2403,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the item background colour."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.Attr().GetBackgroundColour()
 
@@ -2385,7 +2412,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the item font."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.Attr().GetFont()
 
@@ -2394,7 +2421,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether an item is hypertext or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         return item.IsHyperText()
 
@@ -2403,7 +2430,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item text."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         dc = wx.ClientDC(self)
         item.SetText(text)
@@ -2415,7 +2442,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item image, depending on the item state."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         item.SetImage(image, which)
 
@@ -2428,7 +2455,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the data associated to an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         item.SetData(data)
 
@@ -2439,7 +2466,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Forces the appearance of the button next to the item."""
         
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         item.SetHasPlus(has)
         self.RefreshLine(item)
@@ -2449,7 +2476,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item font bold/unbold."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         # avoid redrawing the tree if no real change
         if item.IsBold() != bold:
@@ -2461,7 +2488,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item font italic/non-italic."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         if item.IsItalic() != italic:
             itemFont = self.GetItemFont(item)
@@ -2483,7 +2510,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         if highlight:
             bg = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT)
@@ -2498,7 +2525,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item text colour."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         if self.GetItemTextColour(item) == col:
             return
@@ -2511,7 +2538,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item background colour."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         item.Attr().SetBackgroundColour(col)
         self.RefreshLine(item)
@@ -2521,7 +2548,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets whether the item is hypertext or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "        
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         item.SetHyperText(hyper)
         self.RefreshLine(item)
@@ -2531,7 +2558,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets the item font."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         if self.GetItemFont(item) == font:
             return
@@ -2596,7 +2623,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Sets whether an hypertext item was visited."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         item.SetVisited(visited)
         self.RefreshLine(item)
@@ -2606,7 +2633,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether an hypertext item was visited."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetVisited()            
 
@@ -2778,7 +2805,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the window associated to the item (if any)."""
 
         if not item:
-            raise "\nERROR: Invalid Item"
+            raise Exception("\nERROR: Invalid Item")
         
         return item.GetWindow()
 
@@ -2787,7 +2814,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the window associated to the item is enabled."""
 
         if not item:
-            raise "\nERROR: Invalid Item"
+            raise Exception("\nERROR: Invalid Item")
         
         return item.GetWindowEnabled()
 
@@ -2796,7 +2823,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Enables/disables the window associated to the item."""
 
         if not item:
-            raise "\nERROR: Invalid Item"
+            raise Exception("\nERROR: Invalid Item")
         
         item.SetWindowEnabled(enable)
 
@@ -2810,7 +2837,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Item"
+            raise Exception("\nERROR: Invalid Item")
         
         return item.GetType()
 
@@ -2822,7 +2849,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the item is visible or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         # An item is only visible if it's not a descendant of a collapsed item
         parent = item.GetParent()
@@ -2855,7 +2882,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the item has children or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         # consider that the item does have children if it has the "+" button: it
         # might not have them (if it had never been expanded yet) but then it
@@ -2869,7 +2896,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the item is expanded or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.IsExpanded()
 
@@ -2878,7 +2905,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the item is selected or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.IsSelected()
 
@@ -2887,7 +2914,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the item font is bold or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.IsBold()
 
@@ -2896,7 +2923,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns whether the item font is italic or not."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.IsItalic()
 
@@ -2909,7 +2936,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the item parent."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         return item.GetParent()
 
@@ -2918,7 +2945,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the item first child."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         cookie = 0
         return self.GetNextChild(item, cookie)
@@ -2931,7 +2958,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         children = item.GetChildren()
 
@@ -2952,7 +2979,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the item last child."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         children = item.GetChildren()
         return (len(children) == 0 and [None] or [children[-1]])[0]
@@ -2962,7 +2989,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the next sibling of an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         i = item
         parent = i.GetParent()
@@ -2983,7 +3010,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the previous sibling of an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         i = item
         parent = i.GetParent()
@@ -3003,7 +3030,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the next item. Only for internal use right now."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         i = item
 
@@ -3041,7 +3068,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Returns the next visible item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         id = item
 
@@ -3056,9 +3083,9 @@ class CustomTreeCtrl(wx.ScrolledWindow):
     def GetPrevVisible(self, item):
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
-        raise "\nERROR: Not Implemented"
+        raise Exception("\nERROR: Not Implemented")
 
         return None
 
@@ -3116,13 +3143,13 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Actually inserts an item in the tree."""
 
         if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style 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):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style 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:
-            raise "\nERROR: Item Type Should Be 0 (Normal), 1 (CheckBox) or 2 (RadioButton). "
+            raise Exception("\nERROR: Item Type Should Be 0 (Normal), 1 (CheckBox) or 2 (RadioButton). ")
         
         parent = parentId
         
@@ -3148,16 +3175,16 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Adds a root to the CustomTreeCtrl. Only one root must exist."""
 
         if self._anchor:
-            raise "\nERROR: Tree Can Have Only One Root"
+            raise Exception("\nERROR: Tree Can Have Only One Root")
 
         if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style 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):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style 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:
-            raise "\nERROR: Item Type Should Be 0 (Normal), 1 (CheckBox) or 2 (RadioButton). "
+            raise Exception("\nERROR: Item Type Should Be 0 (Normal), 1 (CheckBox) or 2 (RadioButton). ")
 
         self._dirty = True     # do this first so stuff below doesn't cause flicker
 
@@ -3187,10 +3214,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Appends an item as a first child of parent."""
 
         if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style 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):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style 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)
 
@@ -3199,10 +3226,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Auxiliary function to cope with the C++ hideous multifunction."""
         
         if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style 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):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style 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
         
@@ -3216,7 +3243,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             try:
                 index = parent.GetChildren().index(idPrevious)
             except:
-                raise "ERROR: Previous Item In CustomTreeCtrl.InsertItem() Is Not A Sibling"
+                raise Exception("ERROR: Previous Item In CustomTreeCtrl.InsertItem() Is Not A Sibling")
 
         return self.DoInsertItem(parentId, index+1, text, ct_type, wnd, image, selImage, data)
 
@@ -3225,10 +3252,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Auxiliary function to cope with the C++ hideous multifunction."""
 
         if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style 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):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style 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
         
@@ -3243,10 +3270,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Inserts an item after the given previous."""
 
         if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style 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):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style 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):
             return self.InsertItemByIndex(parentId, input, text, ct_type, wnd, image, selImage, data)
@@ -3258,10 +3285,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Appends an item as a last child of its parent."""
 
         if wnd is not None and not (self._windowStyle & TR_HAS_VARIABLE_ROW_HEIGHT):
-            raise "\nERROR: In Order To Append/Insert Controls You Have To Use The Style 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):
-            raise "\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style 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
         
@@ -3319,7 +3346,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Delete item children."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         self._dirty = True     # do this first so stuff below doesn't cause flicker
 
@@ -3331,7 +3358,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Delete an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         self._dirty = True     # do this first so stuff below doesn't cause flicker
 
@@ -3408,10 +3435,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         if self.HasFlag(TR_HIDE_ROOT) and item == self.GetRootItem():
-             raise "\nERROR: Can't Expand An Hidden Root. "
+             raise Exception("\nERROR: Can't Expand An Hidden Root. ")
 
         if not item.HasPlus():
             return
@@ -3444,9 +3471,9 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Expands all the items."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
-        if not self.HasFlag(TR_HIDE_ROOT) or item != GetRootItem():
+        if not self.HasFlag(TR_HIDE_ROOT) or item != self.GetRootItem():
             self.Expand(item)
             if not self.IsExpanded(item):
                 return
@@ -3465,10 +3492,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         if self.HasFlag(TR_HIDE_ROOT) and item == self.GetRootItem():
-             raise "\nERROR: Can't Collapse An Hidden Root. "
+             raise Exception("\nERROR: Can't Collapse An Hidden Root. ")
 
         if not item.IsExpanded():
             return
@@ -3619,7 +3646,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Actually selects/unselects an item, sending a EVT_TREE_SEL_CHANGED event."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         self._select_me = None
 
@@ -3700,7 +3727,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Selects/deselects an item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
         
         if select:
         
@@ -3724,7 +3751,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         if item.IsSelected():
             array.append(item)
 
-        if item.HasChildren():    
+        if item.HasChildren() and item.IsExpanded():
             for child in item.GetChildren():
                 array = self.FillArray(child, array)
         
@@ -3751,7 +3778,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Ensure that an item is visible in CustomTreeCtrl."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         # first expand all parent branches
         parent = item.GetParent()
@@ -3835,7 +3862,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
 
         children = item.GetChildren()
         
@@ -4057,9 +4084,8 @@ class CustomTreeCtrl(wx.ScrolledWindow):
     def DrawVerticalGradient(self, dc, rect, hasfocus):
         """Gradient fill from colour 1 to colour 2 from top to bottom."""
 
-        dc.DrawRectangleRect(rect)
-        border = self._borderPen.GetWidth()
-        
+        oldpen = dc.GetPen()
+        oldbrush = dc.GetBrush()
         dc.SetPen(wx.TRANSPARENT_PEN)
 
         # calculate gradient coefficients
@@ -4081,21 +4107,25 @@ class CustomTreeCtrl(wx.ScrolledWindow):
 
         rf, gf, bf = 0, 0, 0
         
-        for y in xrange(rect.y+border, rect.y + rect.height-border):
+        for y in xrange(rect.y, rect.y + rect.height):
             currCol = (r1 + rf, g1 + gf, b1 + bf)                
             dc.SetBrush(wx.Brush(currCol, wx.SOLID))
-            dc.DrawRectangle(rect.x+border, y, rect.width-2*border, 1)
+            dc.DrawRectangle(rect.x, y, rect.width, 1)
             rf = rf + rstep
             gf = gf + gstep
             bf = bf + bstep
         
+        dc.SetPen(oldpen)
+        dc.SetBrush(wx.TRANSPARENT_BRUSH)
+        dc.DrawRectangleRect(rect)
+        dc.SetBrush(oldbrush)
+
 
     def DrawHorizontalGradient(self, dc, rect, hasfocus):
         """Gradient fill from colour 1 to colour 2 from left to right."""
 
-        dc.DrawRectangleRect(rect)
-        border = self._borderPen.GetWidth()
-        
+        oldpen = dc.GetPen()
+        oldbrush = dc.GetBrush()
         dc.SetPen(wx.TRANSPARENT_PEN)
 
         # calculate gradient coefficients
@@ -4117,15 +4147,20 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         bstep = float((b2 - b1)) / flrect
 
         rf, gf, bf = 0, 0, 0
-        
-        for x in xrange(rect.x+border, rect.x + rect.width-border):
+
+        for x in xrange(rect.x, rect.x + rect.width):
             currCol = (int(r1 + rf), int(g1 + gf), int(b1 + bf))
             dc.SetBrush(wx.Brush(currCol, wx.SOLID))
-            dc.DrawRectangle(x, rect.y+border, 1, rect.height-2*border)
+            dc.DrawRectangle(x, rect.y, 1, rect.height)
             rf = rf + rstep
             gf = gf + gstep
             bf = bf + bstep
-            
+
+        dc.SetPen(oldpen)
+        dc.SetBrush(wx.TRANSPARENT_BRUSH)
+        dc.DrawRectangleRect(rect)
+        dc.SetBrush(oldbrush)
+        
 
     def DrawVistaRectangle(self, dc, rect, hasfocus):
         """Draw the selected item(s) with the Windows Vista style."""
@@ -4147,18 +4182,14 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         oldpen = dc.GetPen()
         oldbrush = dc.GetBrush()
 
-        dc.SetBrush(wx.TRANSPARENT_BRUSH)
-        dc.SetPen(wx.Pen(outer))
-        dc.DrawRoundedRectangleRect(rect, 3)
-        rect.Deflate(1, 1)
-        dc.SetPen(wx.Pen(inner))
-        dc.DrawRoundedRectangleRect(rect, 2)
-        rect.Deflate(1, 1)
-
+        bdrRect = wx.Rect(*rect.Get())
+        filRect = wx.Rect(*rect.Get())
+        filRect.Deflate(1,1)
+        
         r1, g1, b1 = int(top.Red()), int(top.Green()), int(top.Blue())
         r2, g2, b2 = int(bottom.Red()), int(bottom.Green()), int(bottom.Blue())
 
-        flrect = float(rect.height)
+        flrect = float(filRect.height)
 
         rstep = float((r2 - r1)) / flrect
         gstep = float((g2 - g1)) / flrect
@@ -4167,14 +4198,21 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         rf, gf, bf = 0, 0, 0
         dc.SetPen(wx.TRANSPARENT_PEN)
         
-        for y in xrange(rect.y, rect.y + rect.height):
+        for y in xrange(filRect.y, filRect.y + filRect.height):
             currCol = (r1 + rf, g1 + gf, b1 + bf)
             dc.SetBrush(wx.Brush(currCol, wx.SOLID))
-            dc.DrawRectangle(rect.x, y, rect.width, 1)
+            dc.DrawRectangle(filRect.x, y, filRect.width, 1)
             rf = rf + rstep
             gf = gf + gstep
             bf = bf + bstep
         
+        dc.SetBrush(wx.TRANSPARENT_BRUSH)
+        dc.SetPen(wx.Pen(outer))
+        dc.DrawRoundedRectangleRect(bdrRect, 3)
+        bdrRect.Deflate(1, 1)
+        dc.SetPen(wx.Pen(inner))
+        dc.DrawRoundedRectangleRect(bdrRect, 2)
+
         dc.SetPen(oldpen)
         dc.SetBrush(oldbrush)
 
@@ -4220,7 +4258,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
 
         total_h = self.GetLineHeight(item)
         drawItemBackground = False
-
+            
         if item.IsSelected():
         
             # under mac selections are only a rectangle in case they don't have the focus
@@ -4244,13 +4282,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             dc.SetPen(wx.TRANSPARENT_PEN)
         
         offset = (self.HasFlag(TR_ROW_LINES) and [1] or [0])[0]
-
+        
         if self.HasFlag(TR_FULL_ROW_HIGHLIGHT):
-
-            oldpen = dc.GetPen()
-            dc.SetPen(wx.TRANSPARENT_PEN)
-            x, y = self.GetPosition()
-            w, h = self.GetSize()
+            x = 0
+            w, h = self.GetClientSize()
 
             itemrect = wx.Rect(x, item.GetY()+offset, w, total_h-offset)
             
@@ -4263,13 +4298,16 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                 elif self._vistaselection:
                     self.DrawVistaRectangle(dc, itemrect, self._hasFocus)
                 else:
-                    dc.DrawRectangleRect(itemrect)
+                    if wx.Platform in ["__WXGTK2__", "__WXMAC__"]:
+                        flags = wx.CONTROL_SELECTED
+                        if self._hasFocus: flags = flags | wx.CONTROL_FOCUSED
+                        wx.RendererNative.Get().DrawItemSelectionRect(self, dc, itemrect, flags) 
+                    else:
+                        dc.DrawRectangleRect(itemrect)
 
-            dc.SetPen(oldpen)
-        
         else:
-        
-            if item.IsSelected() and image != _NO_IMAGE:
+
+            if item.IsSelected():
             
                 # If it's selected, and there's an image, then we should
                 # take care to leave the area under the image painted in the
@@ -4280,9 +4318,11 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                 if wnd:
                     wndx, wndy = item.GetWindowSize()
 
-                itemrect = wx.Rect(item.GetX() + wcheck + image_w - 2, item.GetY()+offset,
-                                   item.GetWidth() - image_w - wcheck + 2 - wndx, total_h-offset)
-                
+                itemrect = wx.Rect(item.GetX() + wcheck + image_w - 2,
+                                   item.GetY()+offset,
+                                   item.GetWidth() - image_w - wcheck + 2 - wndx,
+                                   total_h-offset)
+
                 if self._usegradients:
                     if self._gradientstyle == 0:   # Horizontal
                         self.DrawHorizontalGradient(dc, itemrect, self._hasFocus)
@@ -4291,7 +4331,12 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                 elif self._vistaselection:
                     self.DrawVistaRectangle(dc, itemrect, self._hasFocus)
                 else:
-                    dc.DrawRectangleRect(itemrect)
+                    if wx.Platform in ["__WXGTK2__", "__WXMAC__"]:
+                        flags = wx.CONTROL_SELECTED
+                        if self._hasFocus: flags = flags | wx.CONTROL_FOCUSED
+                        wx.RendererNative.Get().DrawItemSelectionRect(self, dc, itemrect, flags) 
+                    else:
+                        dc.DrawRectangleRect(itemrect)
                             
             # On GTK+ 2, drawing a 'normal' background is wrong for themes that
             # don't allow backgrounds to be customized. Not drawing the background,
@@ -4299,7 +4344,10 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             elif drawItemBackground:
 
                 minusicon = wcheck + image_w - 2
-                itemrect = wx.Rect(item.GetX()+minusicon, item.GetY()+offset, item.GetWidth()-minusicon, total_h-offset)
+                itemrect = wx.Rect(item.GetX()+minusicon,
+                                   item.GetY()+offset,
+                                   item.GetWidth()-minusicon,
+                                   total_h-offset)
                                 
                 if self._usegradients and self._hasFocus:
                     if self._gradientstyle == 0:   # Horizontal
@@ -4346,6 +4394,8 @@ class CustomTreeCtrl(wx.ScrolledWindow):
             dc.DrawLabel(item.GetText(), textrect)
             dc.SetTextForeground(foreground)
         else:
+            if wx.Platform == "__WXMAC__" and item.IsSelected() and self._hasFocus:
+                dc.SetTextForeground(wx.WHITE)
             dc.DrawLabel(item.GetText(), textrect)
 
         wnd = item.GetWindow()
@@ -4807,7 +4857,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                         current = self.GetItemParent(current)
                         if current:
                             next = self.GetNextSibling(current)
-                            if not self.IsEnabled(next):
+                            if not next or not self.IsEnabled(next):
                                 next = None
 
                 else:
@@ -4977,7 +5027,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Gets the bounding rectangle of the item."""
 
         if not item:
-            raise "\nERROR: Invalid Tree Item. "
+            raise Exception("\nERROR: Invalid Tree Item. ")
     
         i = item
 
@@ -5082,7 +5132,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         underMouse = thisItem
         underMouseChanged = underMouse != self._underMouse
 
-        if underMouse and (flags & TREE_HITTEST_ONITEMBUTTON) and not event.LeftIsDown() and \
+        if underMouse and (flags & TREE_HITTEST_ONITEM) and not event.LeftIsDown() and \
            not self._isDragging and (not self._renameTimer or not self._renameTimer.IsRunning()):
             underMouse = underMouse
         else:
@@ -5405,7 +5455,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
                         self.Toggle(item)
                         
 
-    def OnInternalIdle(self, event):
+    def OnInternalIdle(self):
         """Performs operations in idle time (essentially drawing)."""
 
         # Check if we need to select the root item
@@ -5615,7 +5665,7 @@ class CustomTreeCtrl(wx.ScrolledWindow):
         """Thaw CustomTreeCtrl."""
 
         if self._freezeCount == 0:
-            raise "\nERROR: Thawing Unfrozen Tree Control?"
+            raise Exception("\nERROR: Thawing Unfrozen Tree Control?")
 
         self._freezeCount = self._freezeCount - 1