External/Aga.Controls/Tree/TreeViewAdv.Properties.cs
author sl
Thu, 01 Jan 2015 23:35:49 +0100
changeset 405 5715aefd2bcc
parent 345 0c551e8818e0
permissions -rw-r--r--
SharpDisplay: Migrating to new robust client scheme.
     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         private static Font _font = SystemFonts.MessageBoxFont; 
   330         /// <summary>
   331         /// The font to render <see cref="TreeViewAdv"/> content in.
   332         /// </summary>
   333         [Category("Appearance"), Description("The font to render TreeViewAdv content in.")]
   334         public override Font Font
   335         {
   336             get
   337             {
   338                 return (base.Font);
   339             }
   340             set
   341             {
   342                 if (value == null)
   343                     base.Font = _font;
   344                 else
   345                 {
   346                     if (value == DefaultFont)
   347                         base.Font = _font;
   348                     else
   349                         base.Font = value;
   350                 }
   351             }
   352         }
   353         public override void ResetFont()
   354         {
   355             Font = null;
   356         }
   357         private bool ShouldSerializeFont()
   358         {
   359             return (!Font.Equals(_font));
   360         }
   361         // End font property
   362 
   363 		private BorderStyle _borderStyle = BorderStyle.Fixed3D;
   364 		[DefaultValue(BorderStyle.Fixed3D), Category("Appearance")]
   365 		public BorderStyle BorderStyle
   366 		{
   367 			get
   368 			{
   369 				return this._borderStyle;
   370 			}
   371 			set
   372 			{
   373 				if (_borderStyle != value)
   374 				{
   375 					_borderStyle = value;
   376 					base.UpdateStyles();
   377 				}
   378 			}
   379 		}
   380 
   381 		private bool _autoRowHeight = false;
   382 		/// <summary>
   383 		/// Set to true to expand each row's height to fit the text of it's largest column.
   384 		/// </summary>
   385 		[DefaultValue(false), Category("Appearance"), Description("Expand each row's height to fit the text of it's largest column.")]
   386 		public bool AutoRowHeight
   387 		{
   388 			get
   389 			{
   390 				return _autoRowHeight;
   391 			}
   392 			set
   393 			{
   394 				_autoRowHeight = value;
   395 				if (value)
   396 					_rowLayout = new AutoRowHeightLayout(this, RowHeight);
   397 				else
   398 					_rowLayout = new FixedRowHeightLayout(this, RowHeight);
   399 				FullUpdate();
   400 			}
   401 		}
   402 
   403         private GridLineStyle _gridLineStyle = GridLineStyle.None;
   404         [DefaultValue(GridLineStyle.None), Category("Appearance")]
   405         public GridLineStyle GridLineStyle
   406         {
   407             get
   408             {
   409                 return _gridLineStyle;
   410             }
   411             set
   412             {
   413 				if (value != _gridLineStyle)
   414 				{
   415 					_gridLineStyle = value;
   416 					UpdateView();
   417 					OnGridLineStyleChanged();
   418 				}
   419             }
   420         }
   421 
   422 		private int _rowHeight = 16;
   423 		[DefaultValue(16), Category("Appearance")]
   424 		public int RowHeight
   425 		{
   426 			get
   427 			{
   428 				return _rowHeight;
   429 			}
   430 			set
   431 			{
   432 				if (value <= 0)
   433 					throw new ArgumentOutOfRangeException("value");
   434 
   435 				_rowHeight = value;
   436 				_rowLayout.PreferredRowHeight = value;
   437 				FullUpdate();
   438 			}
   439 		}
   440 
   441 		private TreeSelectionMode _selectionMode = TreeSelectionMode.Single;
   442 		[DefaultValue(TreeSelectionMode.Single), Category("Behavior")]
   443 		public TreeSelectionMode SelectionMode
   444 		{
   445 			get { return _selectionMode; }
   446 			set { _selectionMode = value; }
   447 		}
   448 
   449 		private bool _hideSelection;
   450 		[DefaultValue(false), Category("Behavior")]
   451 		public bool HideSelection
   452 		{
   453 			get { return _hideSelection; }
   454 			set
   455 			{
   456 				_hideSelection = value;
   457 				UpdateView();
   458 			}
   459 		}
   460 
   461 		private float _topEdgeSensivity = 0.3f;
   462 		[DefaultValue(0.3f), Category("Behavior")]
   463 		public float TopEdgeSensivity
   464 		{
   465 			get { return _topEdgeSensivity; }
   466 			set
   467 			{
   468 				if (value < 0 || value > 1)
   469 					throw new ArgumentOutOfRangeException();
   470 				_topEdgeSensivity = value;
   471 			}
   472 		}
   473 
   474 		private float _bottomEdgeSensivity = 0.3f;
   475 		[DefaultValue(0.3f), Category("Behavior")]
   476 		public float BottomEdgeSensivity
   477 		{
   478 			get { return _bottomEdgeSensivity; }
   479 			set
   480 			{
   481 				if (value < 0 || value > 1)
   482 					throw new ArgumentOutOfRangeException("value should be from 0 to 1");
   483 				_bottomEdgeSensivity = value;
   484 			}
   485 		}
   486 
   487 		private bool _loadOnDemand;
   488 		[DefaultValue(false), Category("Behavior")]
   489 		public bool LoadOnDemand
   490 		{
   491 			get { return _loadOnDemand; }
   492 			set { _loadOnDemand = value; }
   493 		}
   494 
   495 		private bool _unloadCollapsedOnReload = false;
   496 		[DefaultValue(false), Category("Behavior")]
   497 		public bool UnloadCollapsedOnReload
   498 		{
   499 			get { return _unloadCollapsedOnReload; }
   500 			set { _unloadCollapsedOnReload = value; }
   501 		}
   502 
   503 		private int _indent = 19;
   504 		[DefaultValue(19), Category("Behavior")]
   505 		public int Indent
   506 		{
   507 			get { return _indent; }
   508 			set
   509 			{
   510 				_indent = value;
   511 				UpdateView();
   512 			}
   513 		}
   514 
   515 		private Color _lineColor = SystemColors.ControlDark;
   516 		[Category("Behavior")]
   517 		public Color LineColor
   518 		{
   519 			get { return _lineColor; }
   520 			set
   521 			{
   522 				_lineColor = value;
   523 				CreateLinePen();
   524 				UpdateView();
   525 			}
   526 		}
   527 
   528 		private Color _dragDropMarkColor = Color.Black;
   529 		[Category("Behavior")]
   530 		public Color DragDropMarkColor
   531 		{
   532 			get { return _dragDropMarkColor; }
   533 			set
   534 			{
   535 				_dragDropMarkColor = value;
   536 				CreateMarkPen();
   537 			}
   538 		}
   539 
   540 		private float _dragDropMarkWidth = 3.0f;
   541 		[DefaultValue(3.0f), Category("Behavior")]
   542 		public float DragDropMarkWidth
   543 		{
   544 			get { return _dragDropMarkWidth; }
   545 			set
   546 			{
   547 				_dragDropMarkWidth = value;
   548 				CreateMarkPen();
   549 			}
   550 		}
   551 
   552 		private bool _highlightDropPosition = true;
   553 		[DefaultValue(true), Category("Behavior")]
   554 		public bool HighlightDropPosition
   555 		{
   556 			get { return _highlightDropPosition; }
   557 			set { _highlightDropPosition = value; }
   558 		}
   559 
   560 		private TreeColumnCollection _columns;
   561 		[Category("Behavior"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
   562 		public Collection<TreeColumn> Columns
   563 		{
   564 			get { return _columns; }
   565 		}
   566 
   567 		private NodeControlsCollection _controls;
   568 		[Category("Behavior"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
   569 		[Editor(typeof(NodeControlCollectionEditor), typeof(UITypeEditor))]
   570 		public Collection<NodeControl> NodeControls
   571 		{
   572 			get
   573 			{
   574 				return _controls;
   575 			}
   576 		}
   577 
   578 		private bool _asyncExpanding;
   579 		/// <summary>
   580 		/// When set to true, node contents will be read in background thread.
   581 		/// </summary>
   582 		[Category("Behavior"), DefaultValue(false), Description("Read children in a background thread when expanding.")]
   583 		public bool AsyncExpanding
   584 		{
   585 			get { return _asyncExpanding; }
   586 			set { _asyncExpanding = value; }
   587 		}
   588 
   589 		#endregion
   590 
   591 		#region RunTime
   592 
   593 		private IToolTipProvider _defaultToolTipProvider = null;
   594 		[Browsable(false)]
   595 		public IToolTipProvider DefaultToolTipProvider
   596 		{
   597 			get { return _defaultToolTipProvider; }
   598 			set { _defaultToolTipProvider = value; }
   599 		}
   600 
   601 		[Browsable(false)]
   602 		public IEnumerable<TreeNodeAdv> AllNodes
   603 		{
   604 			get
   605 			{
   606 				if (_root.Nodes.Count > 0)
   607 				{
   608 					TreeNodeAdv node = _root.Nodes[0];
   609 					while (node != null)
   610 					{
   611 						yield return node;
   612 						if (node.Nodes.Count > 0)
   613 							node = node.Nodes[0];
   614 						else if (node.NextNode != null)
   615 							node = node.NextNode;
   616 						else
   617 							node = node.BottomNode;
   618 					}
   619 				}
   620 			}
   621 		}
   622 
   623 		private DropPosition _dropPosition;
   624 		[Browsable(false)]
   625 		public DropPosition DropPosition
   626 		{
   627 			get { return _dropPosition; }
   628 			set { _dropPosition = value; }
   629 		}
   630 
   631 		private TreeNodeAdv _root;
   632 		[Browsable(false)]
   633 		public TreeNodeAdv Root
   634 		{
   635 			get { return _root; }
   636 		}
   637 
   638 		private ReadOnlyCollection<TreeNodeAdv> _readonlySelection;
   639 		[Browsable(false)]
   640 		public ReadOnlyCollection<TreeNodeAdv> SelectedNodes
   641 		{
   642 			get
   643 			{
   644 				return _readonlySelection;
   645 			}
   646 		}
   647 
   648 		[Browsable(false)]
   649 		public TreeNodeAdv SelectedNode
   650 		{
   651 			get
   652 			{
   653 				if (Selection.Count > 0)
   654 				{
   655 					if (CurrentNode != null && CurrentNode.IsSelected)
   656 						return CurrentNode;
   657 					else
   658 						return Selection[0];
   659 				}
   660 				else
   661 					return null;
   662 			}
   663 			set
   664 			{
   665 				if (SelectedNode == value)
   666 					return;
   667 
   668 				BeginUpdate();
   669 				try
   670 				{
   671 					if (value == null)
   672 					{
   673 						ClearSelectionInternal();
   674 					}
   675 					else
   676 					{
   677 						if (!IsMyNode(value))
   678 							throw new ArgumentException();
   679 
   680 						ClearSelectionInternal();
   681 						value.IsSelected = true;
   682 						CurrentNode = value;
   683 						EnsureVisible(value);
   684 					}
   685 				}
   686 				finally
   687 				{
   688 					EndUpdate();
   689 				}
   690 			}
   691 		}
   692 
   693 		private TreeNodeAdv _currentNode;
   694 		[Browsable(false)]
   695 		public TreeNodeAdv CurrentNode
   696 		{
   697 			get { return _currentNode; }
   698 			internal set { _currentNode = value; }
   699 		}
   700 
   701         [Browsable(false)]
   702         public int ItemCount
   703         {
   704             get { return RowMap.Count; }
   705         }
   706 
   707 		/// <summary>
   708 		/// Indicates the distance the content is scrolled to the left
   709 		/// </summary>
   710 		[Browsable(false)]
   711 		public int HorizontalScrollPosition
   712 		{
   713 			get
   714 			{
   715 				if (_hScrollBar.Visible)
   716 					return _hScrollBar.Value;
   717 				else
   718 					return 0;
   719 			}
   720 		}
   721 
   722 		#endregion
   723 
   724 		#endregion
   725 
   726 	}
   727 }