BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
BrawlCrate.UI.TreeViewMS Class Reference

http://www.arstdesign.com/articles/treeviewms.html More...

Inheritance diagram for BrawlCrate.UI.TreeViewMS:
BrawlCrate.UI.ResourceTree

Public Member Functions

 TreeViewMS ()
 

Protected Member Functions

override void OnPaint (PaintEventArgs pe)
 
override void OnBeforeSelect (TreeViewCancelEventArgs e)
 
override void OnAfterSelect (TreeViewEventArgs e)
 
bool isParent (TreeNode parentNode, TreeNode childNode)
 
void paintSelectedNodes ()
 
void removePaintFromNodes ()
 

Protected Attributes

List< TreeNode > m_coll
 
TreeNode m_lastNode
 
TreeNode m_firstNode
 

Properties

List< TreeNode > SelectedNodes [get, set]
 
Type SelectedType [get]
 

Detailed Description

http://www.arstdesign.com/articles/treeviewms.html

Constructor & Destructor Documentation

◆ TreeViewMS()

BrawlCrate.UI.TreeViewMS.TreeViewMS ( )
inline
18 {
19 m_coll = new List<TreeNode>();
20 }
List< TreeNode > m_coll
Definition: TreeViewMS.cs:14

Member Function Documentation

◆ isParent()

bool BrawlCrate.UI.TreeViewMS.isParent ( TreeNode  parentNode,
TreeNode  childNode 
)
inlineprotected
245 {
246 if (parentNode == childNode)
247 {
248 return true;
249 }
250
251 TreeNode n = childNode;
252 bool bFound = false;
253 while (!bFound && n != null)
254 {
255 n = n.Parent;
256 bFound = n == parentNode;
257 }
258
259 return bFound;
260 }

◆ OnAfterSelect()

override void BrawlCrate.UI.TreeViewMS.OnAfterSelect ( TreeViewEventArgs  e)
inlineprotected
117 {
118 base.OnAfterSelect(e);
119
120 if (e.Action == TreeViewAction.ByMouse)
121 {
122 bool bControl = ModifierKeys == Keys.Control;
123 bool bShift = ModifierKeys == Keys.Shift;
124
125 if (bControl)
126 {
127 if (!m_coll.Contains(e.Node)) // new node ?
128 {
129 m_coll.Add(e.Node);
130 }
131 else // not new, remove it from the collection
132 {
134 m_coll.Remove(e.Node);
135 }
136
138 }
139 else
140 {
141 // SHIFT is pressed
142 if (bShift)
143 {
144 Queue<TreeNode> myQueue = new Queue<TreeNode>();
145
146 TreeNode uppernode = m_firstNode;
147 TreeNode bottomnode = e.Node;
148 // case 1 : begin and end nodes are parent
149 bool bParent = isParent(m_firstNode, e.Node); // is m_firstNode parent (direct or not) of e.Node
150 if (!bParent)
151 {
152 bParent = isParent(bottomnode, uppernode);
153 if (bParent) // swap nodes
154 {
155 TreeNode t = uppernode;
156 uppernode = bottomnode;
157 bottomnode = t;
158 }
159 }
160
161 if (bParent)
162 {
163 TreeNode n = bottomnode;
164 while (n != (uppernode?.Parent ?? bottomnode))
165 {
166 if (!m_coll.Contains(n)) // new node ?
167 {
168 myQueue.Enqueue(n);
169 }
170
171 n = n.Parent;
172 }
173 }
174 // case 2 : nor the begin nor the end node are descendant one another
175 else
176 {
177 if (uppernode.Parent == null && bottomnode.Parent == null || uppernode.Parent != null &&
178 uppernode.Parent.Nodes.Contains(bottomnode)) // are they siblings ?
179 {
180 int nIndexUpper = uppernode.Index;
181 int nIndexBottom = bottomnode.Index;
182 if (nIndexBottom < nIndexUpper) // reversed?
183 {
184 TreeNode t = uppernode;
185 uppernode = bottomnode;
186 bottomnode = t;
187 nIndexUpper = uppernode.Index;
188 nIndexBottom = bottomnode.Index;
189 }
190
191 TreeNode n = uppernode;
192 while (nIndexUpper <= nIndexBottom)
193 {
194 if (!m_coll.Contains(n)) // new node ?
195 {
196 myQueue.Enqueue(n);
197 }
198
199 n = n.NextNode;
200
201 nIndexUpper++;
202 } // end while
203 }
204 else
205 {
206 if (!m_coll.Contains(uppernode))
207 {
208 myQueue.Enqueue(uppernode);
209 }
210
211 if (!m_coll.Contains(bottomnode))
212 {
213 myQueue.Enqueue(bottomnode);
214 }
215 }
216 }
217
218 m_coll.AddRange(myQueue);
219
221 m_firstNode = e.Node; // let us chain several SHIFTs if we like it
222 } // end if m_bShift
223 else
224 {
225 // in the case of a simple click, just add this item
226 if (m_coll != null && m_coll.Count > 0)
227 {
229 m_coll.Clear();
230 }
231
232 m_coll.Add(e.Node);
233 }
234 }
235 }
236 }
bool isParent(TreeNode parentNode, TreeNode childNode)
Definition: TreeViewMS.cs:244
void removePaintFromNodes()
Definition: TreeViewMS.cs:271
TreeNode m_firstNode
Definition: TreeViewMS.cs:15
void paintSelectedNodes()
Definition: TreeViewMS.cs:262

◆ OnBeforeSelect()

override void BrawlCrate.UI.TreeViewMS.OnBeforeSelect ( TreeViewCancelEventArgs  e)
inlineprotected
78 {
79 base.OnBeforeSelect(e);
80
81 if (e.Action == TreeViewAction.ByMouse)
82 {
83 bool bControl = ModifierKeys == Keys.Control;
84 bool bShift = ModifierKeys == Keys.Shift;
85
86 // selecting twice the node while pressing CTRL ?
87 if (bControl && m_coll.Contains(e.Node))
88 {
89 // unselect it (let framework know we don't want selection this time)
90 e.Cancel = true;
91
92 // update nodes
94 m_coll.Remove(e.Node);
96 return;
97 }
98
99 m_lastNode = e.Node;
100 if (!bShift)
101 {
102 m_firstNode = e.Node; // store begin of shift sequence
103 }
104 }
105 else
106 {
107 if (m_coll != null && m_coll.Count > 0)
108 {
110 m_coll.Clear();
111 }
112 }
113 }
TreeNode m_lastNode
Definition: TreeViewMS.cs:15

◆ OnPaint()

override void BrawlCrate.UI.TreeViewMS.OnPaint ( PaintEventArgs  pe)
inlineprotected
23 {
24 // TODO: Add custom paint code here
25
26 // Calling the base class OnPaint
27 base.OnPaint(pe);
28 }

◆ paintSelectedNodes()

void BrawlCrate.UI.TreeViewMS.paintSelectedNodes ( )
inlineprotected
263 {
264 foreach (TreeNode n in m_coll)
265 {
266 n.BackColor = SystemColors.Highlight;
267 n.ForeColor = SystemColors.HighlightText;
268 }
269 }

◆ removePaintFromNodes()

void BrawlCrate.UI.TreeViewMS.removePaintFromNodes ( )
inlineprotected
272 {
273 if (m_coll.Count == 0)
274 {
275 return;
276 }
277
278 TreeNode n0 = m_coll[0];
279 if (n0.TreeView == null)
280 {
281 return;
282 }
283
284 Color back = n0.TreeView.BackColor;
285 Color fore = n0.TreeView.ForeColor;
286 if (n0 is BaseWrapper b)
287 {
288 if (b.DefaultBackColor != null)
289 {
290 back = (Color) b.DefaultBackColor;
291 }
292
293 if (b.DefaultForeColor != null)
294 {
295 fore = (Color) b.DefaultForeColor;
296 }
297 }
298
299 foreach (TreeNode n in m_coll)
300 {
301 n.BackColor = back;
302 n.ForeColor = fore;
303 }
304 }
Definition: BaseWrapper.cs:71

Member Data Documentation

◆ m_coll

List<TreeNode> BrawlCrate.UI.TreeViewMS.m_coll
protected

◆ m_firstNode

TreeNode BrawlCrate.UI.TreeViewMS.m_firstNode
protected

◆ m_lastNode

TreeNode BrawlCrate.UI.TreeViewMS.m_lastNode
protected

Property Documentation

◆ SelectedNodes

List<TreeNode> BrawlCrate.UI.TreeViewMS.SelectedNodes
getset
32 {
33 get => m_coll;
34 set
35 {
37 m_coll.Clear();
38 m_coll = value;
40 }
41 }

◆ SelectedType

Type BrawlCrate.UI.TreeViewMS.SelectedType
get
44 {
45 get
46 {
47 Type t = SelectedNode?.GetType();
48 if (SelectedNodes.Count > 1)
49 {
50 foreach (TreeNode n in SelectedNodes)
51 {
52 if (!n.GetType().IsAssignableFrom(t))
53 {
54 if (n.GetType().IsAssignableFrom(typeof(GenericWrapper)))
55 {
56 t = typeof(GenericWrapper);
57 }
58 else
59 {
60 t = null;
61 break;
62 }
63 }
64 }
65 }
66
67 return t;
68 }
69 }
Definition: GenericWrapper.cs:17
List< TreeNode > SelectedNodes
Definition: TreeViewMS.cs:32

The documentation for this class was generated from the following file: