/// /// Copyright © 2003-2008 JetBrains s.r.o. /// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder). /// using System; using System.Collections; using System.Drawing; using System.Windows.Forms; namespace JetBrains.JetListViewLibrary { /// /// Specifies the possible modes of anchoring the column in a multiline column scheme. /// [Flags] public enum ColumnAnchor { /// /// The left edge of the column is anchored to the left side of the view area. /// Left = 1, /// /// The right edge of the column is anchored to the right side of the view area. /// Right = 2 } /// /// Describes the layout of a single column in a multiline column scheme. /// public class MultiLineColumnSetting { private JetListViewColumn _column; private readonly int _startRow; private readonly int _endRow; private int _startX; private int _width; private readonly ColumnAnchor _anchor; private readonly Color _textColor; private HorizontalAlignment _textAlign; public MultiLineColumnSetting( JetListViewColumn column, int startRow, int endRow, int startX, int width, ColumnAnchor anchor, Color textColor, HorizontalAlignment textAlign ) { _column = column; _startRow = startRow; _endRow = endRow; _startX = startX; _width = width; _anchor = anchor; _textColor = textColor; _textAlign = textAlign; } public MultiLineColumnSetting( MultiLineColumnSetting rhs ) { _column = rhs._column; _startRow = rhs._startRow; _endRow = rhs._endRow; _startX = rhs._startX; _width = rhs._width; _anchor = rhs._anchor; _textColor = rhs._textColor; _textAlign = rhs._textAlign; } public JetListViewColumn Column { get { return _column; } } public int StartRow { get { return _startRow; } } public int EndRow { get { return _endRow; } } public int StartX { get { return _startX; } set { _startX = value; } } public int Width { get { return _width; } set { _width = value; } } public ColumnAnchor Anchor { get { return _anchor; } } public Color TextColor { get { return _textColor; } } public HorizontalAlignment TextAlign { get { return _textAlign; } } } /// /// Describes the layout of columns for a single item in a multi-column layout. /// public class MultiLineColumnScheme { private ArrayList _columnSettings; private ArrayList _columns; private bool _alignTopLevelItems = false; public MultiLineColumnScheme() { _columnSettings = new ArrayList(); _columns = new ArrayList(); } public MultiLineColumnScheme( MultiLineColumnScheme rhs ) { _columnSettings = new ArrayList( rhs._columnSettings.Count ); foreach( MultiLineColumnSetting setting in rhs._columnSettings ) { _columnSettings.Add( new MultiLineColumnSetting( setting ) ); } _columns = new ArrayList( rhs._columns ); } public IEnumerable ColumnSettings { get { return _columnSettings; } } public ICollection Columns { get { return _columns; } } /// /// Adds a column to the multiline column scheme. /// /// The column to add. /// The row in which the column rectangle starts. /// The row in which the column rectangle ends. /// The X position where the column data starts. /// The width of the column in pixels. /// The anchoring of the columnn to the edges of the view area. /// The color of the text displayed in the column. public void AddColumn( JetListViewColumn column, int startRow, int endRow, int startX, int width, ColumnAnchor anchor, Color textColor, HorizontalAlignment textAlign ) { _columns.Add( column ); _columnSettings.Add( new MultiLineColumnSetting( column, startRow, endRow, startX, width, anchor, textColor, textAlign ) ); } /// /// Returns the base width of the column scheme. /// internal int BaseWidth { get { int maxY = 0; for( int i = 0; i < _columnSettings.Count; ++i ) { MultiLineColumnSetting setting = (MultiLineColumnSetting) _columnSettings[ i ]; int lastY = setting.StartX + setting.Width; if ( lastY > maxY ) { maxY = lastY; } } return maxY; } } /// /// Returns the number of rows in the column scheme. /// public int RowCount { get { int endRow = 0; for( int i = 0; i < _columnSettings.Count; ++i ) { MultiLineColumnSetting setting = (MultiLineColumnSetting) _columnSettings[ i ]; if ( setting.EndRow > endRow ) { endRow = setting.EndRow; } } return endRow+1; } } /// /// Gets or sets the value indicating whether top-level items in a thread /// are aligned even if items have no children. /// public bool AlignTopLevelItems { get { return _alignTopLevelItems; } set { _alignTopLevelItems = value; } } } /// /// Allows to return the column scheme used for the specified item. /// public interface IColumnSchemeProvider { MultiLineColumnScheme GetColumnScheme( object item ); } }