External/Aga.Controls/Tree/TreeViewAdv.Properties.cs
author moel.mich
Sun, 27 May 2012 15:16:19 +0000
changeset 345 0c551e8818e0
child 346 f652ab1e06e2
permissions -rw-r--r--
Added the source code of Aga.Controls (TreeViewAdv for .Net) version 1.7.0.0.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Collections.ObjectModel;
     4 using System.ComponentModel;
     5 using System.Drawing;
     6 using System.Drawing.Design;
     7 using System.Windows.Forms;
     8 
     9 using Aga.Controls.Tree.NodeControls;
    10 
    11 namespace Aga.Controls.Tree
    12 {
    13 	public partial class TreeViewAdv
    14 	{
    15 		private Cursor _innerCursor = null;
    16 
    17 		public override Cursor Cursor
    18 		{
    19 			get
    20 			{
    21                 if (_innerCursor != null)
    22                     return _innerCursor;
    23                 else
    24 					return base.Cursor;
    25 			}
    26 			set
    27 			{
    28 				base.Cursor = value;
    29 			}
    30 		}
    31 
    32 		#region Internal Properties
    33 
    34 		private IRowLayout _rowLayout;
    35 
    36 		private bool _dragMode;
    37 		private bool DragMode
    38 		{
    39 			get { return _dragMode; }
    40 			set
    41 			{
    42 				_dragMode = value;
    43 				if (!value)
    44 				{
    45 					StopDragTimer();
    46 					if (_dragBitmap != null)
    47 						_dragBitmap.Dispose();
    48 					_dragBitmap = null;
    49 				}
    50 				else
    51 					StartDragTimer();
    52 			}
    53 		}
    54 
    55 		internal int ColumnHeaderHeight
    56 		{
    57 			get
    58 			{
    59 				if (UseColumns)
    60 					return _columnHeaderHeight;
    61 				else
    62 					return 0;
    63 			}
    64 		}
    65 
    66 		/// <summary>
    67 		/// returns all nodes, which parent is expanded
    68 		/// </summary>
    69 		private IEnumerable<TreeNodeAdv> VisibleNodes
    70 		{
    71 			get
    72 			{
    73 				TreeNodeAdv node = Root;
    74 				while (node != null)
    75 				{
    76 					node = node.NextVisibleNode;
    77 					if (node != null)
    78 						yield return node;
    79 				}
    80 			}
    81 		}
    82 
    83 		private bool _suspendSelectionEvent;
    84 		internal bool SuspendSelectionEvent
    85 		{
    86 			get { return _suspendSelectionEvent; }
    87 			set
    88 			{
    89 				if (value != _suspendSelectionEvent)
    90 				{
    91 					_suspendSelectionEvent = value;
    92 					if (!_suspendSelectionEvent && _fireSelectionEvent)
    93 						OnSelectionChanged();
    94 				}
    95 			}
    96 		}
    97 
    98 		private List<TreeNodeAdv> _rowMap;
    99 		internal List<TreeNodeAdv> RowMap
   100 		{
   101 			get { return _rowMap; }
   102 		}
   103 
   104 		private TreeNodeAdv _selectionStart;
   105 		internal TreeNodeAdv SelectionStart
   106 		{
   107 			get { return _selectionStart; }
   108 			set { _selectionStart = value; }
   109 		}
   110 
   111 		private InputState _input;
   112 		internal InputState Input
   113 		{
   114 			get { return _input; }
   115 			set
   116 			{
   117 				_input = value;
   118 			}
   119 		}
   120 
   121 		private bool _itemDragMode;
   122 		internal bool ItemDragMode
   123 		{
   124 			get { return _itemDragMode; }
   125 			set { _itemDragMode = value; }
   126 		}
   127 
   128 		private Point _itemDragStart;
   129 		internal Point ItemDragStart
   130 		{
   131 			get { return _itemDragStart; }
   132 			set { _itemDragStart = value; }
   133 		}
   134 
   135 
   136 		/// <summary>
   137 		/// Number of rows fits to the current page
   138 		/// </summary>
   139 		internal int CurrentPageSize
   140 		{
   141 			get
   142 			{
   143 				return _rowLayout.CurrentPageSize;
   144 			}
   145 		}
   146 
   147 		/// <summary>
   148 		/// Number of all visible nodes (which parent is expanded)
   149 		/// </summary>
   150 		internal int RowCount
   151 		{
   152 			get
   153 			{
   154 				return RowMap.Count;
   155 			}
   156 		}
   157 
   158 		private int _contentWidth = 0;
   159 		private int ContentWidth
   160 		{
   161 			get
   162 			{
   163 				return _contentWidth;
   164 			}
   165 		}
   166 
   167 		private int _firstVisibleRow;
   168 		internal int FirstVisibleRow
   169 		{
   170 			get { return _firstVisibleRow; }
   171 			set
   172 			{
   173 				HideEditor();
   174 				_firstVisibleRow = value;
   175 				UpdateView();
   176 			}
   177 		}
   178 
   179 		private int _offsetX;
   180 		public int OffsetX
   181 		{
   182 			get { return _offsetX; }
   183 			private set
   184 			{
   185 				HideEditor();
   186 				_offsetX = value;
   187 				UpdateView();
   188 			}
   189 		}
   190 
   191 		public override Rectangle DisplayRectangle
   192 		{
   193 			get
   194 			{
   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);
   201 			}
   202 		}
   203 
   204 		private List<TreeNodeAdv> _selection;
   205 		internal List<TreeNodeAdv> Selection
   206 		{
   207 			get { return _selection; }
   208 		}
   209 
   210 		#endregion
   211 
   212 		#region Public Properties
   213 
   214 		#region DesignTime
   215 
   216 		private bool _shiftFirstNode;
   217 		[DefaultValue(false), Category("Behavior")]
   218 		public bool ShiftFirstNode
   219 		{
   220 			get { return _shiftFirstNode; }
   221 			set { _shiftFirstNode = value; }
   222 		}
   223 
   224 		private bool _displayDraggingNodes;
   225 		[DefaultValue(false), Category("Behavior")]
   226 		public bool DisplayDraggingNodes
   227 		{
   228 			get { return _displayDraggingNodes; }
   229 			set { _displayDraggingNodes = value; }
   230 		}
   231 
   232 		private bool _fullRowSelect;
   233 		[DefaultValue(false), Category("Behavior")]
   234 		public bool FullRowSelect
   235 		{
   236 			get { return _fullRowSelect; }
   237 			set
   238 			{
   239 				_fullRowSelect = value;
   240 				UpdateView();
   241 			}
   242 		}
   243 
   244 		private bool _useColumns;
   245 		[DefaultValue(false), Category("Behavior")]
   246 		public bool UseColumns
   247 		{
   248 			get { return _useColumns; }
   249 			set
   250 			{
   251 				_useColumns = value;
   252 				FullUpdate();
   253 			}
   254 		}
   255 
   256 		private bool _allowColumnReorder;
   257 		[DefaultValue(false), Category("Behavior")]
   258 		public bool AllowColumnReorder
   259 		{
   260 			get { return _allowColumnReorder; }
   261 			set { _allowColumnReorder = value; }
   262 		}
   263 
   264 		private bool _showLines = true;
   265 		[DefaultValue(true), Category("Behavior")]
   266 		public bool ShowLines
   267 		{
   268 			get { return _showLines; }
   269 			set
   270 			{
   271 				_showLines = value;
   272 				UpdateView();
   273 			}
   274 		}
   275 
   276 		private bool _showPlusMinus = true;
   277 		[DefaultValue(true), Category("Behavior")]
   278 		public bool ShowPlusMinus
   279 		{
   280 			get { return _showPlusMinus; }
   281 			set
   282 			{
   283 				_showPlusMinus = value;
   284 				FullUpdate();
   285 			}
   286 		}
   287 
   288 		private bool _showNodeToolTips = false;
   289 		[DefaultValue(false), Category("Behavior")]
   290 		public bool ShowNodeToolTips
   291 		{
   292 			get { return _showNodeToolTips; }
   293 			set { _showNodeToolTips = value; }
   294 		}
   295 
   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
   298 		{
   299 			get { return true; }
   300 			set {}
   301 		}
   302 
   303 		private ITreeModel _model;
   304         /// <Summary>
   305         /// The model associated with this <see cref="TreeViewAdv"/>.
   306         /// </Summary>
   307         /// <seealso cref="ITreeModel"/>
   308         /// <seealso cref="TreeModel"/>
   309         [Browsable(false)]
   310 		public ITreeModel Model
   311 		{
   312 			get { return _model; }
   313 			set
   314 			{
   315 				if (_model != value)
   316 				{
   317 					AbortBackgroundExpandingThreads();
   318 					if (_model != null)
   319 						UnbindModelEvents();
   320 					_model = value;
   321 					CreateNodes();
   322 					FullUpdate();
   323 					if (_model != null)
   324 						BindModelEvents();
   325 				}
   326 			}
   327 		}
   328 
   329         // Tahoma is the default font
   330         private static Font _font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)), false);
   331         /// <summary>
   332         /// The font to render <see cref="TreeViewAdv"/> content in.
   333         /// </summary>
   334         [Category("Appearance"), Description("The font to render TreeViewAdv content in.")]
   335         public override Font Font
   336         {
   337             get
   338             {
   339                 return (base.Font);
   340             }
   341             set
   342             {
   343                 if (value == null)
   344                     base.Font = _font;
   345                 else
   346                 {
   347                     if (value == DefaultFont)
   348                         base.Font = _font;
   349                     else
   350                         base.Font = value;
   351                 }
   352             }
   353         }
   354         public override void ResetFont()
   355         {
   356             Font = null;
   357         }
   358         private bool ShouldSerializeFont()
   359         {
   360             return (!Font.Equals(_font));
   361         }
   362         // End font property
   363 
   364 		private BorderStyle _borderStyle = BorderStyle.Fixed3D;
   365 		[DefaultValue(BorderStyle.Fixed3D), Category("Appearance")]
   366 		public BorderStyle BorderStyle
   367 		{
   368 			get
   369 			{
   370 				return this._borderStyle;
   371 			}
   372 			set
   373 			{
   374 				if (_borderStyle != value)
   375 				{
   376 					_borderStyle = value;
   377 					base.UpdateStyles();
   378 				}
   379 			}
   380 		}
   381 
   382 		private bool _autoRowHeight = false;
   383 		/// <summary>
   384 		/// Set to true to expand each row's height to fit the text of it's largest column.
   385 		/// </summary>
   386 		[DefaultValue(false), Category("Appearance"), Description("Expand each row's height to fit the text of it's largest column.")]
   387 		public bool AutoRowHeight
   388 		{
   389 			get
   390 			{
   391 				return _autoRowHeight;
   392 			}
   393 			set
   394 			{
   395 				_autoRowHeight = value;
   396 				if (value)
   397 					_rowLayout = new AutoRowHeightLayout(this, RowHeight);
   398 				else
   399 					_rowLayout = new FixedRowHeightLayout(this, RowHeight);
   400 				FullUpdate();
   401 			}
   402 		}
   403 
   404         private GridLineStyle _gridLineStyle = GridLineStyle.None;
   405         [DefaultValue(GridLineStyle.None), Category("Appearance")]
   406         public GridLineStyle GridLineStyle
   407         {
   408             get
   409             {
   410                 return _gridLineStyle;
   411             }
   412             set
   413             {
   414 				if (value != _gridLineStyle)
   415 				{
   416 					_gridLineStyle = value;
   417 					UpdateView();
   418 					OnGridLineStyleChanged();
   419 				}
   420             }
   421         }
   422 
   423 		private int _rowHeight = 16;
   424 		[DefaultValue(16), Category("Appearance")]
   425 		public int RowHeight
   426 		{
   427 			get
   428 			{
   429 				return _rowHeight;
   430 			}
   431 			set
   432 			{
   433 				if (value <= 0)
   434 					throw new ArgumentOutOfRangeException("value");
   435 
   436 				_rowHeight = value;
   437 				_rowLayout.PreferredRowHeight = value;
   438 				FullUpdate();
   439 			}
   440 		}
   441 
   442 		private TreeSelectionMode _selectionMode = TreeSelectionMode.Single;
   443 		[DefaultValue(TreeSelectionMode.Single), Category("Behavior")]
   444 		public TreeSelectionMode SelectionMode
   445 		{
   446 			get { return _selectionMode; }
   447 			set { _selectionMode = value; }
   448 		}
   449 
   450 		private bool _hideSelection;
   451 		[DefaultValue(false), Category("Behavior")]
   452 		public bool HideSelection
   453 		{
   454 			get { return _hideSelection; }
   455 			set
   456 			{
   457 				_hideSelection = value;
   458 				UpdateView();
   459 			}
   460 		}
   461 
   462 		private float _topEdgeSensivity = 0.3f;
   463 		[DefaultValue(0.3f), Category("Behavior")]
   464 		public float TopEdgeSensivity
   465 		{
   466 			get { return _topEdgeSensivity; }
   467 			set
   468 			{
   469 				if (value < 0 || value > 1)
   470 					throw new ArgumentOutOfRangeException();
   471 				_topEdgeSensivity = value;
   472 			}
   473 		}
   474 
   475 		private float _bottomEdgeSensivity = 0.3f;
   476 		[DefaultValue(0.3f), Category("Behavior")]
   477 		public float BottomEdgeSensivity
   478 		{
   479 			get { return _bottomEdgeSensivity; }
   480 			set
   481 			{
   482 				if (value < 0 || value > 1)
   483 					throw new ArgumentOutOfRangeException("value should be from 0 to 1");
   484 				_bottomEdgeSensivity = value;
   485 			}
   486 		}
   487 
   488 		private bool _loadOnDemand;
   489 		[DefaultValue(false), Category("Behavior")]
   490 		public bool LoadOnDemand
   491 		{
   492 			get { return _loadOnDemand; }
   493 			set { _loadOnDemand = value; }
   494 		}
   495 
   496 		private bool _unloadCollapsedOnReload = false;
   497 		[DefaultValue(false), Category("Behavior")]
   498 		public bool UnloadCollapsedOnReload
   499 		{
   500 			get { return _unloadCollapsedOnReload; }
   501 			set { _unloadCollapsedOnReload = value; }
   502 		}
   503 
   504 		private int _indent = 19;
   505 		[DefaultValue(19), Category("Behavior")]
   506 		public int Indent
   507 		{
   508 			get { return _indent; }
   509 			set
   510 			{
   511 				_indent = value;
   512 				UpdateView();
   513 			}
   514 		}
   515 
   516 		private Color _lineColor = SystemColors.ControlDark;
   517 		[Category("Behavior")]
   518 		public Color LineColor
   519 		{
   520 			get { return _lineColor; }
   521 			set
   522 			{
   523 				_lineColor = value;
   524 				CreateLinePen();
   525 				UpdateView();
   526 			}
   527 		}
   528 
   529 		private Color _dragDropMarkColor = Color.Black;
   530 		[Category("Behavior")]
   531 		public Color DragDropMarkColor
   532 		{
   533 			get { return _dragDropMarkColor; }
   534 			set
   535 			{
   536 				_dragDropMarkColor = value;
   537 				CreateMarkPen();
   538 			}
   539 		}
   540 
   541 		private float _dragDropMarkWidth = 3.0f;
   542 		[DefaultValue(3.0f), Category("Behavior")]
   543 		public float DragDropMarkWidth
   544 		{
   545 			get { return _dragDropMarkWidth; }
   546 			set
   547 			{
   548 				_dragDropMarkWidth = value;
   549 				CreateMarkPen();
   550 			}
   551 		}
   552 
   553 		private bool _highlightDropPosition = true;
   554 		[DefaultValue(true), Category("Behavior")]
   555 		public bool HighlightDropPosition
   556 		{
   557 			get { return _highlightDropPosition; }
   558 			set { _highlightDropPosition = value; }
   559 		}
   560 
   561 		private TreeColumnCollection _columns;
   562 		[Category("Behavior"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
   563 		public Collection<TreeColumn> Columns
   564 		{
   565 			get { return _columns; }
   566 		}
   567 
   568 		private NodeControlsCollection _controls;
   569 		[Category("Behavior"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
   570 		[Editor(typeof(NodeControlCollectionEditor), typeof(UITypeEditor))]
   571 		public Collection<NodeControl> NodeControls
   572 		{
   573 			get
   574 			{
   575 				return _controls;
   576 			}
   577 		}
   578 
   579 		private bool _asyncExpanding;
   580 		/// <summary>
   581 		/// When set to true, node contents will be read in background thread.
   582 		/// </summary>
   583 		[Category("Behavior"), DefaultValue(false), Description("Read children in a background thread when expanding.")]
   584 		public bool AsyncExpanding
   585 		{
   586 			get { return _asyncExpanding; }
   587 			set { _asyncExpanding = value; }
   588 		}
   589 
   590 		#endregion
   591 
   592 		#region RunTime
   593 
   594 		private IToolTipProvider _defaultToolTipProvider = null;
   595 		[Browsable(false)]
   596 		public IToolTipProvider DefaultToolTipProvider
   597 		{
   598 			get { return _defaultToolTipProvider; }
   599 			set { _defaultToolTipProvider = value; }
   600 		}
   601 
   602 		[Browsable(false)]
   603 		public IEnumerable<TreeNodeAdv> AllNodes
   604 		{
   605 			get
   606 			{
   607 				if (_root.Nodes.Count > 0)
   608 				{
   609 					TreeNodeAdv node = _root.Nodes[0];
   610 					while (node != null)
   611 					{
   612 						yield return node;
   613 						if (node.Nodes.Count > 0)
   614 							node = node.Nodes[0];
   615 						else if (node.NextNode != null)
   616 							node = node.NextNode;
   617 						else
   618 							node = node.BottomNode;
   619 					}
   620 				}
   621 			}
   622 		}
   623 
   624 		private DropPosition _dropPosition;
   625 		[Browsable(false)]
   626 		public DropPosition DropPosition
   627 		{
   628 			get { return _dropPosition; }
   629 			set { _dropPosition = value; }
   630 		}
   631 
   632 		private TreeNodeAdv _root;
   633 		[Browsable(false)]
   634 		public TreeNodeAdv Root
   635 		{
   636 			get { return _root; }
   637 		}
   638 
   639 		private ReadOnlyCollection<TreeNodeAdv> _readonlySelection;
   640 		[Browsable(false)]
   641 		public ReadOnlyCollection<TreeNodeAdv> SelectedNodes
   642 		{
   643 			get
   644 			{
   645 				return _readonlySelection;
   646 			}
   647 		}
   648 
   649 		[Browsable(false)]
   650 		public TreeNodeAdv SelectedNode
   651 		{
   652 			get
   653 			{
   654 				if (Selection.Count > 0)
   655 				{
   656 					if (CurrentNode != null && CurrentNode.IsSelected)
   657 						return CurrentNode;
   658 					else
   659 						return Selection[0];
   660 				}
   661 				else
   662 					return null;
   663 			}
   664 			set
   665 			{
   666 				if (SelectedNode == value)
   667 					return;
   668 
   669 				BeginUpdate();
   670 				try
   671 				{
   672 					if (value == null)
   673 					{
   674 						ClearSelectionInternal();
   675 					}
   676 					else
   677 					{
   678 						if (!IsMyNode(value))
   679 							throw new ArgumentException();
   680 
   681 						ClearSelectionInternal();
   682 						value.IsSelected = true;
   683 						CurrentNode = value;
   684 						EnsureVisible(value);
   685 					}
   686 				}
   687 				finally
   688 				{
   689 					EndUpdate();
   690 				}
   691 			}
   692 		}
   693 
   694 		private TreeNodeAdv _currentNode;
   695 		[Browsable(false)]
   696 		public TreeNodeAdv CurrentNode
   697 		{
   698 			get { return _currentNode; }
   699 			internal set { _currentNode = value; }
   700 		}
   701 
   702         [Browsable(false)]
   703         public int ItemCount
   704         {
   705             get { return RowMap.Count; }
   706         }
   707 
   708 		/// <summary>
   709 		/// Indicates the distance the content is scrolled to the left
   710 		/// </summary>
   711 		[Browsable(false)]
   712 		public int HorizontalScrollPosition
   713 		{
   714 			get
   715 			{
   716 				if (_hScrollBar.Visible)
   717 					return _hScrollBar.Value;
   718 				else
   719 					return 0;
   720 			}
   721 		}
   722 
   723 		#endregion
   724 
   725 		#endregion
   726 
   727 	}
   728 }