// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-// Copyright (c) 2004 Novell, Inc.
+// Copyright (c) 2004-2005 Novell, Inc.
//
// Authors:
// Jackson Harper (jackson@ximian.com)
+// Kazuki Oikawa (kazuki@panicode.com)
using System;
using System.Text;
private int selected_image_index = -1;
internal TreeNodeCollection nodes;
- private bool is_expanded = true;
+ private bool is_expanded = false;
private Rectangle bounds = Rectangle.Empty;
private Rectangle plus_minus_bounds = Rectangle.Empty;
private Rectangle checkbox_bounds = Rectangle.Empty;
private bool check;
+ private bool is_editing;
internal OwnerDrawPropertyBag prop_bag;
private object tag;
return;
check = value;
- // We should just be invalidating the node
if (TreeView != null)
- tree_view.Refresh ();
+ tree_view.UpdateNode (this);
}
}
public Color BackColor {
get {
- return prop_bag == null ? Color.Empty : prop_bag.BackColor;
+ if (prop_bag != null)
+ return prop_bag.BackColor;
+ if (TreeView != null)
+ return TreeView.BackColor;
+ return Color.Empty;
}
set {
if (prop_bag == null)
}
public Color ForeColor {
- get {
- return prop_bag == null ? Color.Empty : prop_bag.ForeColor;
+ get {
+ if (prop_bag != null)
+ return prop_bag.ForeColor;
+ if (TreeView != null)
+ return TreeView.ForeColor;
+ return Color.Empty;
}
set {
if (prop_bag == null)
public Font NodeFont {
get {
- return prop_bag == null ? null : prop_bag.Font;
+ if (prop_bag != null)
+ return prop_bag.Font;
+ if (TreeView != null)
+ return TreeView.Font;
+ return null;
}
set {
if (prop_bag == null)
set { tag = value; }
}
+ public bool IsSelected {
+ get {
+ if (TreeView == null)
+ return false;
+ return TreeView.SelectedNode == this;
+ }
+ }
+
+ public bool IsEditing {
+ get { return is_editing; }
+ }
+
+ public bool IsVisible {
+ get {
+ if (TreeView == null)
+ return false;
+
+ if (bounds.Y < 0 && bounds.Y > TreeView.ClientRectangle.Height)
+ return false;
+
+ TreeNode parent = Parent;
+ while (parent != null) {
+ if (!parent.IsExpanded)
+ return false;
+ parent = parent.Parent;
+ }
+ return true;
+ }
+ }
+
+ public void BeginEdit ()
+ {
+ is_editing = true;
+ }
+
+ public void EndEdit (bool cancel)
+ {
+ is_editing = false;
+ if (!cancel && TreeView != null)
+ text = TreeView.LabelEditText;
+ }
+
public void Expand ()
+ {
+ Expand(false);
+ }
+ private void Expand (bool byInternal)
{
if (is_expanded)
return;
is_expanded = true;
if (TreeView != null)
TreeView.OnAfterCollapse (new TreeViewEventArgs (this));
- if (IsNodeVisible () && TreeView != null)
+ if (IsVisible && TreeView != null)
TreeView.UpdateBelow (this);
}
}
public void Collapse ()
+ {
+ Collapse(false);
+ }
+
+ private void Collapse (bool byInternal)
{
if (!is_expanded)
return;
is_expanded = false;
if (TreeView != null)
TreeView.OnAfterCollapse (new TreeViewEventArgs (this));
- if (IsNodeVisible () && TreeView != null)
+ if (IsVisible && TreeView != null)
TreeView.UpdateBelow (this);
+ if(!byInternal && TreeView != null && HasFocusInChildren ())
+ TreeView.SelectedNode = this;
+ }
+ }
+
+ private bool HasFocusInChildren()
+ {
+ if(TreeView == null) return false;
+ foreach(TreeNode node in nodes) {
+ if(node == TreeView.SelectedNode) return true;
+ if(node.HasFocusInChildren())
+ return true;
}
+ return false;
}
public void Remove ()
public void ExpandAll ()
{
ExpandRecursive (this);
+ if(TreeView != null)
+ TreeView.Refresh();
}
private void ExpandRecursive (TreeNode node)
{
- node.Expand ();
+ node.Expand (true);
foreach (TreeNode child in node.Nodes) {
ExpandRecursive (child);
}
CollapseRecursive (this);
}
+ internal void CollapseAllUncheck ()
+ {
+ CollapseUncheckRecursive (this);
+ }
+
private void CollapseRecursive (TreeNode node)
{
node.Collapse ();
}
}
+ private void CollapseUncheckRecursive (TreeNode node)
+ {
+ node.Collapse ();
+ node.Checked = false;
+ foreach (TreeNode child in node.Nodes) {
+ CollapseUncheckRecursive (child);
+ }
+ }
+
public int GetNodeCount (bool include_subtrees)
{
if (!include_subtrees)
Collapse ();
else
Expand ();
-
- if (TreeView != null)
- TreeView.Refresh ();
}
internal void SetNodes (TreeNodeCollection nodes)
this.index = index;
}
+ internal void SetIndex (int index)
+ {
+ this.index = index;
+ }
+
private bool IsInClippingRect
{
get {
return true;
}
}
-
- private bool IsNodeVisible ()
- {
- if (TreeView == null)
- return false;
-
- if (bounds.Y < 0 && bounds.Y > TreeView.ClientRectangle.Height)
- return false;
-
- TreeNode parent = Parent;
- while (parent != null) {
- if (!parent.IsExpanded)
- return false;
- parent = parent.Parent;
- }
- return true;
- }
}
}