1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
4 using System
.Collections
.Generic
;
6 using System
.Windows
.Forms
;
8 namespace Aga
.Controls
.Tree
10 internal class NormalInputState
: InputState
12 private bool _mouseDownFlag
= false;
14 public NormalInputState(TreeViewAdv tree
) : base(tree
)
18 public override void KeyDown(KeyEventArgs args
)
20 if (Tree
.CurrentNode
== null && Tree
.Root
.Nodes
.Count
> 0)
21 Tree
.CurrentNode
= Tree
.Root
.Nodes
[0];
23 if (Tree
.CurrentNode
!= null)
28 if (!Tree
.CurrentNode
.IsExpanded
)
29 Tree
.CurrentNode
.IsExpanded
= true;
30 else if (Tree
.CurrentNode
.Nodes
.Count
> 0)
31 Tree
.SelectedNode
= Tree
.CurrentNode
.Nodes
[0];
35 if (Tree
.CurrentNode
.IsExpanded
)
36 Tree
.CurrentNode
.IsExpanded
= false;
37 else if (Tree
.CurrentNode
.Parent
!= Tree
.Root
)
38 Tree
.SelectedNode
= Tree
.CurrentNode
.Parent
;
50 NavigateForward(Math
.Max(1, Tree
.CurrentPageSize
- 1));
54 NavigateBackward(Math
.Max(1, Tree
.CurrentPageSize
- 1));
58 if (Tree
.RowMap
.Count
> 0)
59 FocusRow(Tree
.RowMap
[0]);
63 if (Tree
.RowMap
.Count
> 0)
64 FocusRow(Tree
.RowMap
[Tree
.RowMap
.Count
-1]);
68 Tree
.CurrentNode
.Collapse();
70 args
.SuppressKeyPress
= true;
73 Tree
.CurrentNode
.Expand();
75 args
.SuppressKeyPress
= true;
78 Tree
.CurrentNode
.ExpandAll();
80 args
.SuppressKeyPress
= true;
83 if (args
.Modifiers
== Keys
.Control
)
84 Tree
.SelectAllNodes();
90 public override void MouseDown(TreeNodeAdvMouseEventArgs args
)
92 if (args
.Node
!= null)
94 Tree
.ItemDragMode
= true;
95 Tree
.ItemDragStart
= args
.Location
;
97 if (args
.Button
== MouseButtons
.Left
|| args
.Button
== MouseButtons
.Right
)
102 Tree
.CurrentNode
= args
.Node
;
103 if (args
.Node
.IsSelected
)
104 _mouseDownFlag
= true;
107 _mouseDownFlag
= false;
108 DoMouseOperation(args
);
120 Tree
.ItemDragMode
= false;
121 MouseDownAtEmptySpace(args
);
125 public override void MouseUp(TreeNodeAdvMouseEventArgs args
)
127 Tree
.ItemDragMode
= false;
128 if (_mouseDownFlag
&& args
.Node
!= null)
130 if (args
.Button
== MouseButtons
.Left
)
131 DoMouseOperation(args
);
132 else if (args
.Button
== MouseButtons
.Right
)
133 Tree
.CurrentNode
= args
.Node
;
135 _mouseDownFlag
= false;
139 private void NavigateBackward(int n
)
141 int row
= Math
.Max(Tree
.CurrentNode
.Row
- n
, 0);
142 if (row
!= Tree
.CurrentNode
.Row
)
143 FocusRow(Tree
.RowMap
[row
]);
146 private void NavigateForward(int n
)
148 int row
= Math
.Min(Tree
.CurrentNode
.Row
+ n
, Tree
.RowCount
- 1);
149 if (row
!= Tree
.CurrentNode
.Row
)
150 FocusRow(Tree
.RowMap
[row
]);
153 protected virtual void MouseDownAtEmptySpace(TreeNodeAdvMouseEventArgs args
)
155 Tree
.ClearSelection();
158 protected virtual void FocusRow(TreeNodeAdv node
)
160 Tree
.SuspendSelectionEvent
= true;
163 Tree
.ClearSelectionInternal();
164 Tree
.CurrentNode
= node
;
165 Tree
.SelectionStart
= node
;
166 node
.IsSelected
= true;
171 Tree
.SuspendSelectionEvent
= false;
175 protected bool CanSelect(TreeNodeAdv node
)
177 if (Tree
.SelectionMode
== TreeSelectionMode
.MultiSameParent
)
179 return (Tree
.SelectionStart
== null || node
.Parent
== Tree
.SelectionStart
.Parent
);
185 protected virtual void DoMouseOperation(TreeNodeAdvMouseEventArgs args
)
187 if (Tree
.SelectedNodes
.Count
== 1 && args
.Node
!= null && args
.Node
.IsSelected
)
190 Tree
.SuspendSelectionEvent
= true;
193 Tree
.ClearSelectionInternal();
194 if (args
.Node
!= null)
195 args
.Node
.IsSelected
= true;
196 Tree
.SelectionStart
= args
.Node
;
200 Tree
.SuspendSelectionEvent
= false;