]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/lib/customtreectrl.py
Show GridCellAutoWrapStringRenderer
[wxWidgets.git] / wxPython / wx / lib / customtreectrl.py
index 34a79ba748eb27785f162c5da5f94b13ca3b730b..d987320ca0995015256b3904ff7a91206e085ebe 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()
@@ -1764,6 +1766,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             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.
@@ -2154,6 +2157,9 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         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)
 
@@ -2202,6 +2208,28 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             (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 "\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."""
 
@@ -3443,7 +3471,7 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
         if not item:
             raise "\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
@@ -4268,11 +4296,16 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                 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)
 
         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
@@ -4296,7 +4329,12 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
                 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,
@@ -4354,6 +4392,8 @@ class CustomTreeCtrl(wx.PyScrolledWindow):
             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()