AutoRowHeightLayout.cs :  » GUI » TreeViewAdv » Aga » Controls » Tree » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » TreeViewAdv 
TreeViewAdv » Aga » Controls » Tree » AutoRowHeightLayout.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Aga.Controls.Tree.NodeControls;

namespace Aga.Controls.Tree{
  public class AutoRowHeightLayout: IRowLayout
  {
    private DrawContext _measureContext;
    private TreeViewAdv _treeView;
    private List<Rectangle> _rowCache;

    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));
    }

    private int _rowHeight;
    public int PreferredRowHeight
    {
      get { return _rowHeight; }
      set { _rowHeight = value; }
    }


    public int PageRowCount
    {
      get 
      {
        if (_treeView.RowCount == 0)
          return 0;
        else
        {
          int pageHeight = _treeView.DisplayRectangle.Height - _treeView.ColumnHeaderHeight;
          int y = 0;
          for (int i = _treeView.RowCount - 1; i >= 0; i--)
          {
            y += GetRowHeight(i);
            if (y > pageHeight)
              return Math.Max(0, _treeView.RowCount - 1 - i);
          }
          return _treeView.RowCount;
        }
      }
    }

    public int CurrentPageSize
    {
      get
      {
        if (_treeView.RowCount == 0)
          return 0;
        else
        {
          int pageHeight = _treeView.DisplayRectangle.Height - _treeView.ColumnHeaderHeight;
          int y = 0;
          for (int i = _treeView.FirstVisibleRow; i < _treeView.RowCount; i++)
          {
            y += GetRowHeight(i);
            if (y > pageHeight)
              return Math.Max(0, i - _treeView.FirstVisibleRow);
          }
          return Math.Max(0, _treeView.RowCount - _treeView.FirstVisibleRow);
        }
      }
    }

    public Rectangle GetRowBounds(int rowNo)
    {
      if (rowNo >= _rowCache.Count)
      {
        int count = _rowCache.Count;
        int y = count > 0 ? _rowCache[count - 1].Bottom : 0;
        for (int i = count; i <= rowNo; i++)
        {
          int height = GetRowHeight(i);
          _rowCache.Add(new Rectangle(0, y, 0, height));
          y += height;
        }
        if (rowNo < _rowCache.Count - 1)
          return Rectangle.Empty;
      }
      if (rowNo >= 0 && rowNo < _rowCache.Count)
        return _rowCache[rowNo];
      else
        return Rectangle.Empty;
    }

    private int GetRowHeight(int rowNo)
    {
      if (rowNo < _treeView.RowMap.Count)
      {
        TreeNodeAdv node = _treeView.RowMap[rowNo];
        if (node.Height == null)
        {
          int res = 0;
          _measureContext.Font = _treeView.Font;
          foreach (NodeControl nc in _treeView.NodeControls)
          {
            int h = nc.GetActualSize(node, _measureContext).Height;
            if (h > res)
              res = h;
          }
          node.Height = res;
        }
        return node.Height.Value;
      }
      else
        return 0;
    }

    public int GetRowAt(Point point)
    {
      int py = point.Y - _treeView.ColumnHeaderHeight;
      int y = 0;
      for (int i = _treeView.FirstVisibleRow; i < _treeView.RowCount; i++)
      {
        int h = GetRowHeight(i);
        if (py >= y && py < y + h)
          return i;
        else
          y += h;
      }
      return -1;
    }

    public int GetFirstRow(int lastPageRow)
    {
      int pageHeight = _treeView.DisplayRectangle.Height - _treeView.ColumnHeaderHeight;
      int y = 0;
      for (int i = lastPageRow; i >= 0; i--)
      {
        y += GetRowHeight(i);
        if (y > pageHeight)
          return Math.Max(0, i + 1);
      }
      return 0;
    }

    public void ClearCache()
    {
      _rowCache.Clear();
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.