예제 #1
0
 public AutoRowHeightLayout(TreeViewAdv treeView, int rowHeight)
 {
     _rowCache = new List<Rectangle>();
     _treeView = treeView;
     PreferredRowHeight = rowHeight;
     _measureContext = new DrawContext();
     _measureContext.Graphics = Graphics.FromImage(new Bitmap(1, 1));
 }
예제 #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            BeginPerformanceCount();
            PerformanceAnalyzer.Start("OnPaint");

            DrawContext context = new DrawContext();
            context.Graphics = e.Graphics;
            context.Font = this.Font;
            context.Enabled = Enabled;

            int y = 0;
            int gridHeight = 0;

            if (UseColumns)
            {
                DrawColumnHeaders(e.Graphics);
                y += ColumnHeaderHeight;
                if (Columns.Count == 0 || e.ClipRectangle.Height <= y)
                    return;
            }

            int firstRowY = _rowLayout.GetRowBounds(FirstVisibleRow).Y;
            y -= firstRowY;

            e.Graphics.ResetTransform();
            e.Graphics.TranslateTransform(-OffsetX, y);
            Rectangle displayRect = DisplayRectangle;
            for (int row = FirstVisibleRow; row < RowCount; row++)
            {
                Rectangle rowRect = _rowLayout.GetRowBounds(row);
                gridHeight += rowRect.Height;
                if (rowRect.Y + y > displayRect.Bottom)
                    break;
                else
                    DrawRow(e, ref context, row, rowRect);
            }

            if ((GridLineStyle & GridLineStyle.Vertical) == GridLineStyle.Vertical && UseColumns)
                DrawVerticalGridLines(e.Graphics, firstRowY);

            if (_dropPosition.Node != null && DragMode && HighlightDropPosition)
                DrawDropMark(e.Graphics);

            e.Graphics.ResetTransform();
            DrawScrollBarsBox(e.Graphics);

            if (DragMode && _dragBitmap != null)
                e.Graphics.DrawImage(_dragBitmap, PointToClient(MousePosition));

            PerformanceAnalyzer.Finish("OnPaint");
            EndPerformanceCount(e);
        }
예제 #3
0
 public void DrawNode(TreeNodeAdv node, DrawContext context)
 {
     foreach (NodeControlInfo item in GetNodeControls(node))
     {
         if (item.Bounds.X >= OffsetX && item.Bounds.X - OffsetX < this.Bounds.Width)// skip invisible nodes
         {
             context.Bounds = item.Bounds;
             context.Graphics.SetClip(context.Bounds);
             item.Control.Draw(node, context);
             context.Graphics.ResetClip();
         }
     }
 }
예제 #4
0
        public TreeViewAdv()
        {
            InitializeComponent();
            SetStyle(ControlStyles.AllPaintingInWmPaint
                | ControlStyles.UserPaint
                | ControlStyles.OptimizedDoubleBuffer
                | ControlStyles.ResizeRedraw
                | ControlStyles.Selectable
                , true);

            if (Application.RenderWithVisualStyles)
                _columnHeaderHeight = 20;
            else
                _columnHeaderHeight = 17;

            //BorderStyle = BorderStyle.Fixed3D;
            _hScrollBar.Height = SystemInformation.HorizontalScrollBarHeight;
            _vScrollBar.Width = SystemInformation.VerticalScrollBarWidth;
            _rowLayout = new FixedRowHeightLayout(this, RowHeight);
            _rowMap = new List<TreeNodeAdv>();
            _selection = new List<TreeNodeAdv>();
            _readonlySelection = new ReadOnlyCollection<TreeNodeAdv>(_selection);
            _columns = new TreeColumnCollection(this);
            _toolTip = new ToolTip();

            _measureContext = new DrawContext();
            _measureContext.Font = Font;
            _measureContext.Graphics = Graphics.FromImage(new Bitmap(1, 1));

            Input = new NormalInputState(this);
            _search = new IncrementalSearch(this);
            CreateNodes();
            CreatePens();

            ArrangeControls();

            _plusMinus = new NodePlusMinus();
            _controls = new NodeControlsCollection(this);

            ExpandingIcon.IconChanged += ExpandingIconChanged;
        }
예제 #5
0
        private void DrawRow(PaintEventArgs e, ref DrawContext context, int row, Rectangle rowRect)
        {
            TreeNodeAdv node = RowMap[row];
            context.DrawSelection = DrawSelectionMode.None;
            context.CurrentEditorOwner = _currentEditorOwner;
            if (DragMode)
            {
                if ((_dropPosition.Node == node) && _dropPosition.Position == NodePosition.Inside && HighlightDropPosition)
                    context.DrawSelection = DrawSelectionMode.Active;
            }
            else
            {
                if (node.IsSelected && Focused)
                    context.DrawSelection = DrawSelectionMode.Active;
                else if (node.IsSelected && !Focused && !HideSelection)
                    context.DrawSelection = DrawSelectionMode.Inactive;
            }
            context.DrawFocus = Focused && CurrentNode == node;

            if (FullRowSelect)
            {
                context.DrawFocus = false;
                if (context.DrawSelection == DrawSelectionMode.Active || context.DrawSelection == DrawSelectionMode.Inactive)
                {
                    Rectangle focusRect = new Rectangle(OffsetX, rowRect.Y, ClientRectangle.Width, rowRect.Height);
                    if (context.DrawSelection == DrawSelectionMode.Active)
                    {
                        e.Graphics.FillRectangle(SystemBrushes.Highlight, focusRect);
                        context.DrawSelection = DrawSelectionMode.FullRowSelect;
                    }
                    else
                    {
                        e.Graphics.FillRectangle(SystemBrushes.InactiveBorder, focusRect);
                        context.DrawSelection = DrawSelectionMode.None;
                    }
                }
            }

            if ((GridLineStyle & GridLineStyle.Horizontal) == GridLineStyle.Horizontal)
                e.Graphics.DrawLine(SystemPens.InactiveBorder, 0, rowRect.Bottom, e.Graphics.ClipBounds.Right, rowRect.Bottom);

            if (ShowLines)
                DrawLines(e.Graphics, node, rowRect);

            DrawNode(node, context);
        }
예제 #6
0
 private void DrawIcons()
 {
     Graphics gr = Graphics.FromHwnd(this.Handle);
     int firstRowY = _rowLayout.GetRowBounds(FirstVisibleRow).Y;
     DrawContext context = new DrawContext();
     context.Graphics = gr;
     for (int i = 0; i < _expandingNodes.Count; i++)
     {
         foreach (NodeControlInfo info in GetNodeControls(_expandingNodes[i]))
             if (info.Control is ExpandingIcon)
             {
                 Rectangle rect = info.Bounds;
                 rect.X -= OffsetX;
                 rect.Y -= firstRowY;
                 context.Bounds = rect;
                 info.Control.Draw(info.Node, context);
             }
     }
     gr.Dispose();
 }
예제 #7
0
        private void CreateDragBitmap(IDataObject data)
        {
            if (UseColumns || !DisplayDraggingNodes)
                return;

            TreeNodeAdv[] nodes = data.GetData(typeof(TreeNodeAdv[])) as TreeNodeAdv[];
            if (nodes != null && nodes.Length > 0)
            {
                Rectangle rect = DisplayRectangle;
                Bitmap bitmap = new Bitmap(rect.Width, rect.Height);
                using (Graphics gr = Graphics.FromImage(bitmap))
                {
                    gr.Clear(BackColor);
                    DrawContext context = new DrawContext();
                    context.Graphics = gr;
                    context.Font = Font;
                    context.Enabled = true;
                    int y = 0;
                    int maxWidth = 0;
                    foreach (TreeNodeAdv node in nodes)
                    {
                        if (node.Tree == this)
                        {
                            int x = 0;
                            int height = _rowLayout.GetRowBounds(node.Row).Height;
                            foreach (NodeControl c in NodeControls)
                            {
                                Size s = c.GetActualSize(node, context);
                                if (!s.IsEmpty)
                                {
                                    int width = s.Width;
                                    rect = new Rectangle(x, y, width, height);
                                    x += (width + 1);
                                    context.Bounds = rect;
                                    c.Draw(node, context);
                                }
                            }
                            y += height;
                            maxWidth = Math.Max(maxWidth, x);
                        }
                    }

                    if (maxWidth > 0 && y > 0)
                    {
                        _dragBitmap = new Bitmap(maxWidth, y, PixelFormat.Format32bppArgb);
                        using (Graphics tgr = Graphics.FromImage(_dragBitmap))
                            tgr.DrawImage(bitmap, Point.Empty);
                        BitmapHelper.SetAlphaChanelValue(_dragBitmap, 150);
                    }
                    else
                        _dragBitmap = null;
                }
            }
        }
예제 #8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            BeginPerformanceCount();
            PerformanceAnalyzer.Start("OnPaint");

            DrawContext context = new DrawContext();

            context.Graphics = e.Graphics;
            context.Font     = this.Font;
            context.Enabled  = Enabled;

            int y          = 0;
            int gridHeight = 0;

            if (UseColumns)
            {
                DrawColumnHeaders(e.Graphics);
                y += ColumnHeaderHeight;
                if (Columns.Count == 0 || e.ClipRectangle.Height <= y)
                {
                    return;
                }
            }

            int firstRowY = _rowLayout.GetRowBounds(FirstVisibleRow).Y;

            y -= firstRowY;

            e.Graphics.ResetTransform();
            e.Graphics.TranslateTransform(-OffsetX, y);
            Rectangle displayRect = DisplayRectangle;

            for (int row = FirstVisibleRow; row < RowCount; row++)
            {
                Rectangle rowRect = _rowLayout.GetRowBounds(row);
                gridHeight += rowRect.Height;
                if (rowRect.Y + y > displayRect.Bottom)
                {
                    break;
                }
                else
                {
                    DrawRow(e, ref context, row, rowRect);
                }
            }

            if ((GridLineStyle & GridLineStyle.Vertical) == GridLineStyle.Vertical && UseColumns)
            {
                DrawVerticalGridLines(e.Graphics, firstRowY);
            }

            if (_dropPosition.Node != null && DragMode && HighlightDropPosition)
            {
                DrawDropMark(e.Graphics);
            }

            e.Graphics.ResetTransform();
            DrawScrollBarsBox(e.Graphics);

            if (DragMode && _dragBitmap != null)
            {
                e.Graphics.DrawImage(_dragBitmap, PointToClient(MousePosition));
            }

            PerformanceAnalyzer.Finish("OnPaint");
            EndPerformanceCount(e);
        }