Added the source code of the WinRing0 device driver.
2 using System.Collections.Generic;
4 using System.Windows.Forms;
6 using Aga.Controls.Tree.NodeControls;
7 using System.Drawing.Imaging;
8 using System.Threading;
10 namespace Aga.Controls.Tree
12 public partial class TreeViewAdv
16 protected override bool IsInputChar(char charCode)
21 protected override bool IsInputKey(Keys keyData)
23 if (((keyData & Keys.Up) == Keys.Up)
24 || ((keyData & Keys.Down) == Keys.Down)
25 || ((keyData & Keys.Left) == Keys.Left)
26 || ((keyData & Keys.Right) == Keys.Right))
29 return base.IsInputKey(keyData);
32 internal void ChangeInput()
34 if ((ModifierKeys & Keys.Shift) == Keys.Shift)
36 if (!(Input is InputWithShift))
37 Input = new InputWithShift(this);
39 else if ((ModifierKeys & Keys.Control) == Keys.Control)
41 if (!(Input is InputWithControl))
42 Input = new InputWithControl(this);
46 if (!(Input.GetType() == typeof(NormalInputState)))
47 Input = new NormalInputState(this);
51 protected override void OnKeyDown(KeyEventArgs e)
56 if (e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.ControlKey)
61 foreach (NodeControlInfo item in GetNodeControls(CurrentNode))
63 item.Control.KeyDown(e);
71 protected override void OnKeyUp(KeyEventArgs e)
76 if (e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.ControlKey)
80 foreach (NodeControlInfo item in GetNodeControls(CurrentNode))
82 item.Control.KeyUp(e);
90 protected override void OnKeyPress(KeyPressEventArgs e)
94 _search.Search(e.KeyChar);
101 private TreeNodeAdvMouseEventArgs CreateMouseArgs(MouseEventArgs e)
103 TreeNodeAdvMouseEventArgs args = new TreeNodeAdvMouseEventArgs(e);
104 args.ViewLocation = new Point(e.X + OffsetX,
105 e.Y + _rowLayout.GetRowBounds(FirstVisibleRow).Y - ColumnHeaderHeight);
106 args.ModifierKeys = ModifierKeys;
107 args.Node = GetNodeAt(e.Location);
108 NodeControlInfo info = GetNodeControlInfoAt(args.Node, e.Location);
109 args.ControlBounds = info.Bounds;
110 args.Control = info.Control;
114 protected override void OnMouseWheel(MouseEventArgs e)
117 if (SystemInformation.MouseWheelScrollLines > 0)
119 int lines = e.Delta / 120 * SystemInformation.MouseWheelScrollLines;
120 int newValue = _vScrollBar.Value - lines;
121 newValue = Math.Min(_vScrollBar.Maximum - _vScrollBar.LargeChange + 1, newValue);
122 newValue = Math.Min(_vScrollBar.Maximum, newValue);
123 _vScrollBar.Value = Math.Max(_vScrollBar.Minimum, newValue);
125 base.OnMouseWheel(e);
128 protected override void OnMouseDown(MouseEventArgs e)
130 if (CurrentEditorOwner != null)
132 CurrentEditorOwner.EndEdit(true);
140 if (e.Button == MouseButtons.Left)
143 c = GetColumnDividerAt(e.Location);
146 Input = new ResizeColumnState(this, c, e.Location);
149 c = GetColumnAt(e.Location);
152 Input = new ClickColumnState(this, c, e.Location);
159 TreeNodeAdvMouseEventArgs args = CreateMouseArgs(e);
161 if (args.Node != null && args.Control != null)
162 args.Control.MouseDown(args);
165 Input.MouseDown(args);
170 protected override void OnMouseClick(MouseEventArgs e)
172 //TODO: Disable when click on plusminus icon
173 TreeNodeAdvMouseEventArgs args = CreateMouseArgs(e);
174 if (args.Node != null)
175 OnNodeMouseClick(args);
177 base.OnMouseClick(e);
180 protected override void OnMouseDoubleClick(MouseEventArgs e)
182 TreeNodeAdvMouseEventArgs args = CreateMouseArgs(e);
184 if (args.Node != null && args.Control != null)
185 args.Control.MouseDoubleClick(args);
189 if (args.Node != null)
190 OnNodeMouseDoubleClick(args);
192 Input.MouseDoubleClick(args);
196 if (args.Node != null && args.Button == MouseButtons.Left)
197 args.Node.IsExpanded = !args.Node.IsExpanded;
201 base.OnMouseDoubleClick(e);
204 protected override void OnMouseUp(MouseEventArgs e)
206 TreeNodeAdvMouseEventArgs args = CreateMouseArgs(e);
207 if (Input is ResizeColumnState)
211 if (args.Node != null && args.Control != null)
212 args.Control.MouseUp(args);
220 protected override void OnMouseMove(MouseEventArgs e)
222 if (Input.MouseMove(e))
228 if (ItemDragMode && Dist(e.Location, ItemDragStart) > ItemDragSensivity
229 && CurrentNode != null && CurrentNode.IsSelected)
231 ItemDragMode = false;
232 _toolTip.Active = false;
233 OnItemDrag(e.Button, Selection.ToArray());
237 protected override void OnMouseLeave(EventArgs e)
241 base.OnMouseLeave(e);
244 private void SetCursor(MouseEventArgs e)
247 col = GetColumnDividerAt(e.Location);
253 _innerCursor = ResourceHelper.DVSplitCursor;
255 _innerCursor = Cursors.VSplit;
258 col = GetColumnAt(e.Location);
259 if (col != _hotColumn)
266 internal TreeColumn GetColumnAt(Point p)
268 if (p.Y > ColumnHeaderHeight)
272 foreach (TreeColumn col in Columns)
276 Rectangle rect = new Rectangle(x, 0, col.Width, ColumnHeaderHeight);
278 if (rect.Contains(p))
285 internal int GetColumnX(TreeColumn column)
288 foreach (TreeColumn col in Columns)
301 internal TreeColumn GetColumnDividerAt(Point p)
303 if (p.Y > ColumnHeaderHeight)
307 TreeColumn prevCol = null;
308 Rectangle left, right;
309 foreach (TreeColumn col in Columns)
315 left = new Rectangle(x, 0, DividerWidth / 2, ColumnHeaderHeight);
316 right = new Rectangle(x + col.Width - (DividerWidth / 2), 0, DividerWidth / 2, ColumnHeaderHeight);
317 if (left.Contains(p) && prevCol != null)
319 else if (right.Contains(p))
327 left = new Rectangle(x, 0, DividerWidth / 2, ColumnHeaderHeight);
328 if (left.Contains(p) && prevCol != null)
334 TreeColumn _tooltipColumn;
335 private void UpdateToolTip(MouseEventArgs e)
337 TreeColumn col = GetColumnAt(e.Location);
340 if (col != _tooltipColumn)
341 SetTooltip(col.TooltipText);
344 DisplayNodesTooltip(e);
345 _tooltipColumn = col;
348 TreeNodeAdv _hotNode;
349 NodeControl _hotControl;
350 private void DisplayNodesTooltip(MouseEventArgs e)
352 if (ShowNodeToolTips)
354 TreeNodeAdvMouseEventArgs args = CreateMouseArgs(e);
355 if (args.Node != null && args.Control != null)
357 if (args.Node != _hotNode || args.Control != _hotControl)
358 SetTooltip(GetNodeToolTip(args));
361 _toolTip.SetToolTip(this, null);
363 _hotControl = args.Control;
364 _hotNode = args.Node;
367 _toolTip.SetToolTip(this, null);
370 private void SetTooltip(string text)
372 if (!String.IsNullOrEmpty(text))
374 _toolTip.Active = false;
375 _toolTip.SetToolTip(this, text);
376 _toolTip.Active = true;
379 _toolTip.SetToolTip(this, null);
382 private string GetNodeToolTip(TreeNodeAdvMouseEventArgs args)
384 string msg = args.Control.GetToolTip(args.Node);
386 BaseTextControl btc = args.Control as BaseTextControl;
387 if (btc != null && btc.DisplayHiddenContentInToolTip && String.IsNullOrEmpty(msg))
389 Size ms = btc.GetActualSize(args.Node, _measureContext);
390 if (ms.Width > args.ControlBounds.Size.Width || ms.Height > args.ControlBounds.Size.Height
391 || args.ControlBounds.Right - OffsetX > DisplayRectangle.Width)
392 msg = btc.GetLabel(args.Node);
395 if (String.IsNullOrEmpty(msg) && DefaultToolTipProvider != null)
396 msg = DefaultToolTipProvider.GetToolTip(args.Node, args.Control);
405 private bool _dragAutoScrollFlag = false;
406 private Bitmap _dragBitmap = null;
407 private System.Threading.Timer _dragTimer;
409 private void StartDragTimer()
411 if (_dragTimer == null)
412 _dragTimer = new System.Threading.Timer(new TimerCallback(DragTimerTick), null, 0, 100);
415 private void StopDragTimer()
417 if (_dragTimer != null)
419 _dragTimer.Dispose();
424 private void SetDropPosition(Point pt)
426 TreeNodeAdv node = GetNodeAt(pt);
427 OnDropNodeValidating(pt, ref node);
428 _dropPosition.Node = node;
431 Rectangle first = _rowLayout.GetRowBounds(FirstVisibleRow);
432 Rectangle bounds = _rowLayout.GetRowBounds(node.Row);
433 float pos = (pt.Y + first.Y - ColumnHeaderHeight - bounds.Y) / (float)bounds.Height;
434 if (pos < TopEdgeSensivity)
435 _dropPosition.Position = NodePosition.Before;
436 else if (pos > (1 - BottomEdgeSensivity))
437 _dropPosition.Position = NodePosition.After;
439 _dropPosition.Position = NodePosition.Inside;
443 private void DragTimerTick(object state)
445 _dragAutoScrollFlag = true;
448 private void DragAutoScroll()
450 _dragAutoScrollFlag = false;
451 Point pt = PointToClient(MousePosition);
452 if (pt.Y < 20 && _vScrollBar.Value > 0)
454 else if (pt.Y > Height - 20 && _vScrollBar.Value <= _vScrollBar.Maximum - _vScrollBar.LargeChange)
458 public void DoDragDropSelectedNodes(DragDropEffects allowedEffects)
460 if (SelectedNodes.Count > 0)
462 TreeNodeAdv[] nodes = new TreeNodeAdv[SelectedNodes.Count];
463 SelectedNodes.CopyTo(nodes, 0);
464 DoDragDrop(nodes, allowedEffects);
468 private void CreateDragBitmap(IDataObject data)
470 if (UseColumns || !DisplayDraggingNodes)
473 TreeNodeAdv[] nodes = data.GetData(typeof(TreeNodeAdv[])) as TreeNodeAdv[];
474 if (nodes != null && nodes.Length > 0)
476 Rectangle rect = DisplayRectangle;
477 Bitmap bitmap = new Bitmap(rect.Width, rect.Height);
478 using (Graphics gr = Graphics.FromImage(bitmap))
481 DrawContext context = new DrawContext();
482 context.Graphics = gr;
484 context.Enabled = true;
487 foreach (TreeNodeAdv node in nodes)
489 if (node.Tree == this)
492 int height = _rowLayout.GetRowBounds(node.Row).Height;
493 foreach (NodeControl c in NodeControls)
495 Size s = c.GetActualSize(node, context);
499 rect = new Rectangle(x, y, width, height);
501 context.Bounds = rect;
502 c.Draw(node, context);
506 maxWidth = Math.Max(maxWidth, x);
510 if (maxWidth > 0 && y > 0)
512 _dragBitmap = new Bitmap(maxWidth, y, PixelFormat.Format32bppArgb);
513 using (Graphics tgr = Graphics.FromImage(_dragBitmap))
514 tgr.DrawImage(bitmap, Point.Empty);
515 BitmapHelper.SetAlphaChanelValue(_dragBitmap, 150);
523 protected override void OnDragOver(DragEventArgs drgevent)
525 ItemDragMode = false;
526 Point pt = PointToClient(new Point(drgevent.X, drgevent.Y));
527 if (_dragAutoScrollFlag)
531 base.OnDragOver(drgevent);
534 protected override void OnDragEnter(DragEventArgs drgevent)
538 CreateDragBitmap(drgevent.Data);
539 base.OnDragEnter(drgevent);
542 protected override void OnDragLeave(EventArgs e)
549 protected override void OnDragDrop(DragEventArgs drgevent)
553 base.OnDragDrop(drgevent);