Added the source code of Aga.Controls (TreeViewAdv for .Net) version 1.7.0.0.
2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using System.ComponentModel;
6 using System.Drawing.Design;
7 using System.Windows.Forms;
9 using Aga.Controls.Tree.NodeControls;
11 namespace Aga.Controls.Tree
13 public partial class TreeViewAdv
15 private Cursor _innerCursor = null;
17 public override Cursor Cursor
21 if (_innerCursor != null)
32 #region Internal Properties
34 private IRowLayout _rowLayout;
36 private bool _dragMode;
39 get { return _dragMode; }
46 if (_dragBitmap != null)
47 _dragBitmap.Dispose();
55 internal int ColumnHeaderHeight
60 return _columnHeaderHeight;
67 /// returns all nodes, which parent is expanded
69 private IEnumerable<TreeNodeAdv> VisibleNodes
73 TreeNodeAdv node = Root;
76 node = node.NextVisibleNode;
83 private bool _suspendSelectionEvent;
84 internal bool SuspendSelectionEvent
86 get { return _suspendSelectionEvent; }
89 if (value != _suspendSelectionEvent)
91 _suspendSelectionEvent = value;
92 if (!_suspendSelectionEvent && _fireSelectionEvent)
98 private List<TreeNodeAdv> _rowMap;
99 internal List<TreeNodeAdv> RowMap
101 get { return _rowMap; }
104 private TreeNodeAdv _selectionStart;
105 internal TreeNodeAdv SelectionStart
107 get { return _selectionStart; }
108 set { _selectionStart = value; }
111 private InputState _input;
112 internal InputState Input
114 get { return _input; }
121 private bool _itemDragMode;
122 internal bool ItemDragMode
124 get { return _itemDragMode; }
125 set { _itemDragMode = value; }
128 private Point _itemDragStart;
129 internal Point ItemDragStart
131 get { return _itemDragStart; }
132 set { _itemDragStart = value; }
137 /// Number of rows fits to the current page
139 internal int CurrentPageSize
143 return _rowLayout.CurrentPageSize;
148 /// Number of all visible nodes (which parent is expanded)
150 internal int RowCount
158 private int _contentWidth = 0;
159 private int ContentWidth
163 return _contentWidth;
167 private int _firstVisibleRow;
168 internal int FirstVisibleRow
170 get { return _firstVisibleRow; }
174 _firstVisibleRow = value;
179 private int _offsetX;
182 get { return _offsetX; }
191 public override Rectangle DisplayRectangle
195 Rectangle r = ClientRectangle;
196 //r.Y += ColumnHeaderHeight;
197 //r.Height -= ColumnHeaderHeight;
198 int w = _vScrollBar.Visible ? _vScrollBar.Width : 0;
199 int h = _hScrollBar.Visible ? _hScrollBar.Height : 0;
200 return new Rectangle(r.X, r.Y, r.Width - w, r.Height - h);
204 private List<TreeNodeAdv> _selection;
205 internal List<TreeNodeAdv> Selection
207 get { return _selection; }
212 #region Public Properties
216 private bool _shiftFirstNode;
217 [DefaultValue(false), Category("Behavior")]
218 public bool ShiftFirstNode
220 get { return _shiftFirstNode; }
221 set { _shiftFirstNode = value; }
224 private bool _displayDraggingNodes;
225 [DefaultValue(false), Category("Behavior")]
226 public bool DisplayDraggingNodes
228 get { return _displayDraggingNodes; }
229 set { _displayDraggingNodes = value; }
232 private bool _fullRowSelect;
233 [DefaultValue(false), Category("Behavior")]
234 public bool FullRowSelect
236 get { return _fullRowSelect; }
239 _fullRowSelect = value;
244 private bool _useColumns;
245 [DefaultValue(false), Category("Behavior")]
246 public bool UseColumns
248 get { return _useColumns; }
256 private bool _allowColumnReorder;
257 [DefaultValue(false), Category("Behavior")]
258 public bool AllowColumnReorder
260 get { return _allowColumnReorder; }
261 set { _allowColumnReorder = value; }
264 private bool _showLines = true;
265 [DefaultValue(true), Category("Behavior")]
266 public bool ShowLines
268 get { return _showLines; }
276 private bool _showPlusMinus = true;
277 [DefaultValue(true), Category("Behavior")]
278 public bool ShowPlusMinus
280 get { return _showPlusMinus; }
283 _showPlusMinus = value;
288 private bool _showNodeToolTips = false;
289 [DefaultValue(false), Category("Behavior")]
290 public bool ShowNodeToolTips
292 get { return _showNodeToolTips; }
293 set { _showNodeToolTips = value; }
296 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "value"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), DefaultValue(true), Category("Behavior"), Obsolete("No longer used")]
297 public bool KeepNodesExpanded
303 private ITreeModel _model;
305 /// The model associated with this <see cref="TreeViewAdv"/>.
307 /// <seealso cref="ITreeModel"/>
308 /// <seealso cref="TreeModel"/>
310 public ITreeModel Model
312 get { return _model; }
317 AbortBackgroundExpandingThreads();
329 // Tahoma is the default font
330 private static Font _font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)), false);
332 /// The font to render <see cref="TreeViewAdv"/> content in.
334 [Category("Appearance"), Description("The font to render TreeViewAdv content in.")]
335 public override Font Font
347 if (value == DefaultFont)
354 public override void ResetFont()
358 private bool ShouldSerializeFont()
360 return (!Font.Equals(_font));
364 private BorderStyle _borderStyle = BorderStyle.Fixed3D;
365 [DefaultValue(BorderStyle.Fixed3D), Category("Appearance")]
366 public BorderStyle BorderStyle
370 return this._borderStyle;
374 if (_borderStyle != value)
376 _borderStyle = value;
382 private bool _autoRowHeight = false;
384 /// Set to true to expand each row's height to fit the text of it's largest column.
386 [DefaultValue(false), Category("Appearance"), Description("Expand each row's height to fit the text of it's largest column.")]
387 public bool AutoRowHeight
391 return _autoRowHeight;
395 _autoRowHeight = value;
397 _rowLayout = new AutoRowHeightLayout(this, RowHeight);
399 _rowLayout = new FixedRowHeightLayout(this, RowHeight);
404 private GridLineStyle _gridLineStyle = GridLineStyle.None;
405 [DefaultValue(GridLineStyle.None), Category("Appearance")]
406 public GridLineStyle GridLineStyle
410 return _gridLineStyle;
414 if (value != _gridLineStyle)
416 _gridLineStyle = value;
418 OnGridLineStyleChanged();
423 private int _rowHeight = 16;
424 [DefaultValue(16), Category("Appearance")]
434 throw new ArgumentOutOfRangeException("value");
437 _rowLayout.PreferredRowHeight = value;
442 private TreeSelectionMode _selectionMode = TreeSelectionMode.Single;
443 [DefaultValue(TreeSelectionMode.Single), Category("Behavior")]
444 public TreeSelectionMode SelectionMode
446 get { return _selectionMode; }
447 set { _selectionMode = value; }
450 private bool _hideSelection;
451 [DefaultValue(false), Category("Behavior")]
452 public bool HideSelection
454 get { return _hideSelection; }
457 _hideSelection = value;
462 private float _topEdgeSensivity = 0.3f;
463 [DefaultValue(0.3f), Category("Behavior")]
464 public float TopEdgeSensivity
466 get { return _topEdgeSensivity; }
469 if (value < 0 || value > 1)
470 throw new ArgumentOutOfRangeException();
471 _topEdgeSensivity = value;
475 private float _bottomEdgeSensivity = 0.3f;
476 [DefaultValue(0.3f), Category("Behavior")]
477 public float BottomEdgeSensivity
479 get { return _bottomEdgeSensivity; }
482 if (value < 0 || value > 1)
483 throw new ArgumentOutOfRangeException("value should be from 0 to 1");
484 _bottomEdgeSensivity = value;
488 private bool _loadOnDemand;
489 [DefaultValue(false), Category("Behavior")]
490 public bool LoadOnDemand
492 get { return _loadOnDemand; }
493 set { _loadOnDemand = value; }
496 private bool _unloadCollapsedOnReload = false;
497 [DefaultValue(false), Category("Behavior")]
498 public bool UnloadCollapsedOnReload
500 get { return _unloadCollapsedOnReload; }
501 set { _unloadCollapsedOnReload = value; }
504 private int _indent = 19;
505 [DefaultValue(19), Category("Behavior")]
508 get { return _indent; }
516 private Color _lineColor = SystemColors.ControlDark;
517 [Category("Behavior")]
518 public Color LineColor
520 get { return _lineColor; }
529 private Color _dragDropMarkColor = Color.Black;
530 [Category("Behavior")]
531 public Color DragDropMarkColor
533 get { return _dragDropMarkColor; }
536 _dragDropMarkColor = value;
541 private float _dragDropMarkWidth = 3.0f;
542 [DefaultValue(3.0f), Category("Behavior")]
543 public float DragDropMarkWidth
545 get { return _dragDropMarkWidth; }
548 _dragDropMarkWidth = value;
553 private bool _highlightDropPosition = true;
554 [DefaultValue(true), Category("Behavior")]
555 public bool HighlightDropPosition
557 get { return _highlightDropPosition; }
558 set { _highlightDropPosition = value; }
561 private TreeColumnCollection _columns;
562 [Category("Behavior"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
563 public Collection<TreeColumn> Columns
565 get { return _columns; }
568 private NodeControlsCollection _controls;
569 [Category("Behavior"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
570 [Editor(typeof(NodeControlCollectionEditor), typeof(UITypeEditor))]
571 public Collection<NodeControl> NodeControls
579 private bool _asyncExpanding;
581 /// When set to true, node contents will be read in background thread.
583 [Category("Behavior"), DefaultValue(false), Description("Read children in a background thread when expanding.")]
584 public bool AsyncExpanding
586 get { return _asyncExpanding; }
587 set { _asyncExpanding = value; }
594 private IToolTipProvider _defaultToolTipProvider = null;
596 public IToolTipProvider DefaultToolTipProvider
598 get { return _defaultToolTipProvider; }
599 set { _defaultToolTipProvider = value; }
603 public IEnumerable<TreeNodeAdv> AllNodes
607 if (_root.Nodes.Count > 0)
609 TreeNodeAdv node = _root.Nodes[0];
613 if (node.Nodes.Count > 0)
614 node = node.Nodes[0];
615 else if (node.NextNode != null)
616 node = node.NextNode;
618 node = node.BottomNode;
624 private DropPosition _dropPosition;
626 public DropPosition DropPosition
628 get { return _dropPosition; }
629 set { _dropPosition = value; }
632 private TreeNodeAdv _root;
634 public TreeNodeAdv Root
636 get { return _root; }
639 private ReadOnlyCollection<TreeNodeAdv> _readonlySelection;
641 public ReadOnlyCollection<TreeNodeAdv> SelectedNodes
645 return _readonlySelection;
650 public TreeNodeAdv SelectedNode
654 if (Selection.Count > 0)
656 if (CurrentNode != null && CurrentNode.IsSelected)
666 if (SelectedNode == value)
674 ClearSelectionInternal();
678 if (!IsMyNode(value))
679 throw new ArgumentException();
681 ClearSelectionInternal();
682 value.IsSelected = true;
684 EnsureVisible(value);
694 private TreeNodeAdv _currentNode;
696 public TreeNodeAdv CurrentNode
698 get { return _currentNode; }
699 internal set { _currentNode = value; }
705 get { return RowMap.Count; }
709 /// Indicates the distance the content is scrolled to the left
712 public int HorizontalScrollPosition
716 if (_hScrollBar.Visible)
717 return _hScrollBar.Value;