/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs
C# | 6146 lines | 4896 code | 1034 blank | 216 comment | 1208 complexity | 82fcde204b50bdb8de5297c923a606eb MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // Copyright (c) 2004-2005 Novell, Inc. (http://www.novell.com)
- //
- // Authors:
- // Ravindra Kumar (rkumar@novell.com)
- // Jordi Mas i Hernandez, jordi@ximian.com
- // Mike Kestner (mkestner@novell.com)
- // Daniel Nauck (dna(at)mono-project(dot)de)
- // Carlos Alberto Cortez <calberto.cortez@gmail.com>
- //
- // NOT COMPLETE
- using System.Collections;
- using System.ComponentModel;
- using System.ComponentModel.Design;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using System.Globalization;
- using System.Collections.Generic;
- namespace System.Windows.Forms
- {
- [DefaultEvent ("SelectedIndexChanged")]
- [DefaultProperty ("Items")]
- [Designer ("System.Windows.Forms.Design.ListViewDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
- [ClassInterface (ClassInterfaceType.AutoDispatch)]
- [ComVisible (true)]
- [Docking (DockingBehavior.Ask)]
- public class ListView : Control
- {
- private ItemActivation activation = ItemActivation.Standard;
- private ListViewAlignment alignment = ListViewAlignment.Top;
- private bool allow_column_reorder;
- private bool auto_arrange = true;
- private bool check_boxes;
- private readonly CheckedIndexCollection checked_indices;
- private readonly CheckedListViewItemCollection checked_items;
- private readonly ColumnHeaderCollection columns;
- internal int focused_item_index = -1;
- private bool full_row_select;
- private bool grid_lines;
- private ColumnHeaderStyle header_style = ColumnHeaderStyle.Clickable;
- private bool hide_selection = true;
- private bool hover_selection;
- private IComparer item_sorter;
- private readonly ListViewItemCollection items;
- private readonly ListViewGroupCollection groups;
- private bool owner_draw;
- private bool show_groups = true;
- private bool label_edit;
- private bool label_wrap = true;
- private bool multiselect = true;
- private bool scrollable = true;
- private bool hover_pending;
- private readonly SelectedIndexCollection selected_indices;
- private readonly SelectedListViewItemCollection selected_items;
- private SortOrder sort_order = SortOrder.None;
- private ImageList state_image_list;
- internal bool updating;
- private View view = View.LargeIcon;
- private int layout_wd; // We might draw more than our client area
- private int layout_ht; // therefore we need to have these two.
- internal HeaderControl header_control;
- internal ItemControl item_control;
- internal ScrollBar h_scroll; // used for scrolling horizontally
- internal ScrollBar v_scroll; // used for scrolling vertically
- internal int h_marker; // Position markers for scrolling
- internal int v_marker;
- private int keysearch_tickcnt;
- private string keysearch_text;
- static private readonly int keysearch_keydelay = 1000;
- private int[] reordered_column_indices;
- private int[] reordered_items_indices;
- private Point [] items_location;
- private ItemMatrixLocation [] items_matrix_location;
- private Size item_size; // used for caching item size
- private int custom_column_width; // used when using Columns with SmallIcon/List views
- private int hot_item_index = -1;
- private bool hot_tracking;
- private ListViewInsertionMark insertion_mark;
- private bool show_item_tooltips;
- private ToolTip item_tooltip;
- private Size tile_size;
- private bool virtual_mode;
- private int virtual_list_size;
- private bool right_to_left_layout;
- // selection is available after the first time the handle is created, *even* if later
- // the handle is either recreated or destroyed - so keep this info around.
- private bool is_selection_available;
- // internal variables
- internal ImageList large_image_list;
- internal ImageList small_image_list;
- internal Size text_size = Size.Empty;
- #region Events
- static object AfterLabelEditEvent = new object ();
- static object BeforeLabelEditEvent = new object ();
- static object ColumnClickEvent = new object ();
- static object ItemActivateEvent = new object ();
- static object ItemCheckEvent = new object ();
- static object ItemDragEvent = new object ();
- static object SelectedIndexChangedEvent = new object ();
- static object DrawColumnHeaderEvent = new object();
- static object DrawItemEvent = new object();
- static object DrawSubItemEvent = new object();
- static object ItemCheckedEvent = new object ();
- static object ItemMouseHoverEvent = new object ();
- static object ItemSelectionChangedEvent = new object ();
- static object CacheVirtualItemsEvent = new object ();
- static object RetrieveVirtualItemEvent = new object ();
- static object RightToLeftLayoutChangedEvent = new object ();
- static object SearchForVirtualItemEvent = new object ();
- static object VirtualItemsSelectionRangeChangedEvent = new object ();
- public event LabelEditEventHandler AfterLabelEdit {
- add { Events.AddHandler (AfterLabelEditEvent, value); }
- remove { Events.RemoveHandler (AfterLabelEditEvent, value); }
- }
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public new event EventHandler BackgroundImageLayoutChanged {
- add { base.BackgroundImageLayoutChanged += value; }
- remove { base.BackgroundImageLayoutChanged -= value; }
- }
- public event LabelEditEventHandler BeforeLabelEdit {
- add { Events.AddHandler (BeforeLabelEditEvent, value); }
- remove { Events.RemoveHandler (BeforeLabelEditEvent, value); }
- }
- public event ColumnClickEventHandler ColumnClick {
- add { Events.AddHandler (ColumnClickEvent, value); }
- remove { Events.RemoveHandler (ColumnClickEvent, value); }
- }
- public event DrawListViewColumnHeaderEventHandler DrawColumnHeader {
- add { Events.AddHandler(DrawColumnHeaderEvent, value); }
- remove { Events.RemoveHandler(DrawColumnHeaderEvent, value); }
- }
- public event DrawListViewItemEventHandler DrawItem {
- add { Events.AddHandler(DrawItemEvent, value); }
- remove { Events.RemoveHandler(DrawItemEvent, value); }
- }
- public event DrawListViewSubItemEventHandler DrawSubItem {
- add { Events.AddHandler(DrawSubItemEvent, value); }
- remove { Events.RemoveHandler(DrawSubItemEvent, value); }
- }
- public event EventHandler ItemActivate {
- add { Events.AddHandler (ItemActivateEvent, value); }
- remove { Events.RemoveHandler (ItemActivateEvent, value); }
- }
- public event ItemCheckEventHandler ItemCheck {
- add { Events.AddHandler (ItemCheckEvent, value); }
- remove { Events.RemoveHandler (ItemCheckEvent, value); }
- }
- public event ItemCheckedEventHandler ItemChecked {
- add { Events.AddHandler (ItemCheckedEvent, value); }
- remove { Events.RemoveHandler (ItemCheckedEvent, value); }
- }
- public event ItemDragEventHandler ItemDrag {
- add { Events.AddHandler (ItemDragEvent, value); }
- remove { Events.RemoveHandler (ItemDragEvent, value); }
- }
- public event ListViewItemMouseHoverEventHandler ItemMouseHover {
- add { Events.AddHandler (ItemMouseHoverEvent, value); }
- remove { Events.RemoveHandler (ItemMouseHoverEvent, value); }
- }
- public event ListViewItemSelectionChangedEventHandler ItemSelectionChanged {
- add { Events.AddHandler (ItemSelectionChangedEvent, value); }
- remove { Events.RemoveHandler (ItemSelectionChangedEvent, value); }
- }
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public new event EventHandler PaddingChanged {
- add { base.PaddingChanged += value; }
- remove { base.PaddingChanged -= value; }
- }
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public new event PaintEventHandler Paint {
- add { base.Paint += value; }
- remove { base.Paint -= value; }
- }
- public event EventHandler SelectedIndexChanged {
- add { Events.AddHandler (SelectedIndexChangedEvent, value); }
- remove { Events.RemoveHandler (SelectedIndexChangedEvent, value); }
- }
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public new event EventHandler TextChanged {
- add { base.TextChanged += value; }
- remove { base.TextChanged -= value; }
- }
- public event CacheVirtualItemsEventHandler CacheVirtualItems {
- add { Events.AddHandler (CacheVirtualItemsEvent, value); }
- remove { Events.RemoveHandler (CacheVirtualItemsEvent, value); }
- }
- public event RetrieveVirtualItemEventHandler RetrieveVirtualItem {
- add { Events.AddHandler (RetrieveVirtualItemEvent, value); }
- remove { Events.RemoveHandler (RetrieveVirtualItemEvent, value); }
- }
- public event EventHandler RightToLeftLayoutChanged {
- add { Events.AddHandler (RightToLeftLayoutChangedEvent, value); }
- remove { Events.RemoveHandler (RightToLeftLayoutChangedEvent, value); }
- }
- public event SearchForVirtualItemEventHandler SearchForVirtualItem {
- add { Events.AddHandler (SearchForVirtualItemEvent, value); }
- remove { Events.AddHandler (SearchForVirtualItemEvent, value); }
- }
-
- public event ListViewVirtualItemsSelectionRangeChangedEventHandler VirtualItemsSelectionRangeChanged {
- add { Events.AddHandler (VirtualItemsSelectionRangeChangedEvent, value); }
- remove { Events.RemoveHandler (VirtualItemsSelectionRangeChangedEvent, value); }
- }
- #endregion // Events
- #region Public Constructors
- public ListView ()
- {
- background_color = ThemeEngine.Current.ColorWindow;
- groups = new ListViewGroupCollection (this);
- items = new ListViewItemCollection (this);
- items.Changed += new CollectionChangedHandler (OnItemsChanged);
- checked_indices = new CheckedIndexCollection (this);
- checked_items = new CheckedListViewItemCollection (this);
- columns = new ColumnHeaderCollection (this);
- foreground_color = SystemColors.WindowText;
- selected_indices = new SelectedIndexCollection (this);
- selected_items = new SelectedListViewItemCollection (this);
- items_location = new Point [16];
- items_matrix_location = new ItemMatrixLocation [16];
- reordered_items_indices = new int [16];
- item_tooltip = new ToolTip ();
- item_tooltip.Active = false;
- insertion_mark = new ListViewInsertionMark (this);
- InternalBorderStyle = BorderStyle.Fixed3D;
- header_control = new HeaderControl (this);
- header_control.Visible = false;
- Controls.AddImplicit (header_control);
- item_control = new ItemControl (this);
- Controls.AddImplicit (item_control);
- h_scroll = new ImplicitHScrollBar ();
- Controls.AddImplicit (this.h_scroll);
- v_scroll = new ImplicitVScrollBar ();
- Controls.AddImplicit (this.v_scroll);
- h_marker = v_marker = 0;
- keysearch_tickcnt = 0;
- // scroll bars are disabled initially
- h_scroll.Visible = false;
- h_scroll.ValueChanged += new EventHandler(HorizontalScroller);
- v_scroll.Visible = false;
- v_scroll.ValueChanged += new EventHandler(VerticalScroller);
- // event handlers
- base.KeyDown += new KeyEventHandler(ListView_KeyDown);
- SizeChanged += new EventHandler (ListView_SizeChanged);
- GotFocus += new EventHandler (FocusChanged);
- LostFocus += new EventHandler (FocusChanged);
- MouseWheel += new MouseEventHandler(ListView_MouseWheel);
- MouseEnter += new EventHandler (ListView_MouseEnter);
- Invalidated += new InvalidateEventHandler (ListView_Invalidated);
- BackgroundImageTiled = false;
- this.SetStyle (ControlStyles.UserPaint | ControlStyles.StandardClick
- | ControlStyles.UseTextForAccessibility
- , false);
- }
- #endregion // Public Constructors
- #region Private Internal Properties
- internal Size CheckBoxSize {
- get {
- if (this.check_boxes) {
- if (this.state_image_list != null)
- return this.state_image_list.ImageSize;
- else
- return ThemeEngine.Current.ListViewCheckBoxSize;
- }
- return Size.Empty;
- }
- }
- internal Size ItemSize {
- get {
- if (view != View.Details)
- return item_size;
- Size size = new Size ();
- size.Height = item_size.Height;
- for (int i = 0; i < columns.Count; i++)
- size.Width += columns [i].Wd;
- return size;
- }
- set {
- item_size = value;
- }
- }
- internal int HotItemIndex {
- get {
- return hot_item_index;
- }
- set {
- hot_item_index = value;
- }
- }
- internal bool UsingGroups {
- get {
- return show_groups && groups.Count > 0 && view != View.List &&
- Application.VisualStylesEnabled;
- }
- }
- internal override bool ScaleChildrenInternal {
- get { return false; }
- }
- internal bool UseCustomColumnWidth {
- get {
- return (view == View.List || view == View.SmallIcon) && columns.Count > 0;
- }
- }
- internal ColumnHeader EnteredColumnHeader {
- get {
- return header_control.EnteredColumnHeader;
- }
- }
- #endregion // Private Internal Properties
- #region Protected Properties
- protected override CreateParams CreateParams {
- get { return base.CreateParams; }
- }
- protected override Size DefaultSize {
- get { return ThemeEngine.Current.ListViewDefaultSize; }
- }
- protected override bool DoubleBuffered {
- get {
- return base.DoubleBuffered;
- }
- set {
- base.DoubleBuffered = value;
- }
- }
- #endregion // Protected Properties
- #region Public Instance Properties
- [DefaultValue (ItemActivation.Standard)]
- public ItemActivation Activation {
- get { return activation; }
- set {
- if (value != ItemActivation.Standard && value != ItemActivation.OneClick &&
- value != ItemActivation.TwoClick) {
- throw new InvalidEnumArgumentException (string.Format
- ("Enum argument value '{0}' is not valid for Activation", value));
- }
- if (hot_tracking && value != ItemActivation.OneClick)
- throw new ArgumentException ("When HotTracking is on, activation must be ItemActivation.OneClick");
-
- activation = value;
- }
- }
- [DefaultValue (ListViewAlignment.Top)]
- [Localizable (true)]
- public ListViewAlignment Alignment {
- get { return alignment; }
- set {
- if (value != ListViewAlignment.Default && value != ListViewAlignment.Left &&
- value != ListViewAlignment.SnapToGrid && value != ListViewAlignment.Top) {
- throw new InvalidEnumArgumentException (string.Format
- ("Enum argument value '{0}' is not valid for Alignment", value));
- }
-
- if (this.alignment != value) {
- alignment = value;
- // alignment does not matter in Details/List views
- if (this.view == View.LargeIcon || this.View == View.SmallIcon)
- this.Redraw (true);
- }
- }
- }
- [DefaultValue (false)]
- public bool AllowColumnReorder {
- get { return allow_column_reorder; }
- set { allow_column_reorder = value; }
- }
- [DefaultValue (true)]
- public bool AutoArrange {
- get { return auto_arrange; }
- set {
- if (auto_arrange != value) {
- auto_arrange = value;
- // autoarrange does not matter in Details/List views
- if (this.view == View.LargeIcon || this.View == View.SmallIcon)
- this.Redraw (true);
- }
- }
- }
- public override Color BackColor {
- get {
- if (background_color.IsEmpty)
- return ThemeEngine.Current.ColorWindow;
- else
- return background_color;
- }
- set {
- background_color = value;
- item_control.BackColor = value;
- }
- }
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public override ImageLayout BackgroundImageLayout {
- get {
- return base.BackgroundImageLayout;
- }
- set {
- base.BackgroundImageLayout = value;
- }
- }
- [DefaultValue (false)]
- public bool BackgroundImageTiled {
- get {
- return item_control.BackgroundImageLayout == ImageLayout.Tile;
- }
- set {
- ImageLayout new_image_layout = value ? ImageLayout.Tile : ImageLayout.None;
- if (new_image_layout == item_control.BackgroundImageLayout)
- return;
- item_control.BackgroundImageLayout = new_image_layout;
- }
- }
- [DefaultValue (BorderStyle.Fixed3D)]
- [DispId (-504)]
- public BorderStyle BorderStyle {
- get { return InternalBorderStyle; }
- set { InternalBorderStyle = value; }
- }
- [DefaultValue (false)]
- public bool CheckBoxes {
- get { return check_boxes; }
- set {
- if (check_boxes != value) {
- if (value && View == View.Tile)
- throw new NotSupportedException ("CheckBoxes are not"
- + " supported in Tile view. Choose a different"
- + " view or set CheckBoxes to false.");
- check_boxes = value;
- this.Redraw (true);
- //UIA Framework: Event used by ListView to set/unset Toggle Pattern
- OnUIACheckBoxesChanged ();
- }
- }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public CheckedIndexCollection CheckedIndices {
- get { return checked_indices; }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public CheckedListViewItemCollection CheckedItems {
- get { return checked_items; }
- }
- [Editor ("System.Windows.Forms.Design.ColumnHeaderCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [Localizable (true)]
- [MergableProperty (false)]
- public ColumnHeaderCollection Columns {
- get { return columns; }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public ListViewItem FocusedItem {
- get {
- if (focused_item_index == -1)
- return null;
- return GetItemAtDisplayIndex (focused_item_index);
- }
- set {
- if (value == null || value.ListView != this ||
- !IsHandleCreated)
- return;
- SetFocusedItem (value.DisplayIndex);
- }
- }
- public override Color ForeColor {
- get {
- if (foreground_color.IsEmpty)
- return ThemeEngine.Current.ColorWindowText;
- else
- return foreground_color;
- }
- set { foreground_color = value; }
- }
- [DefaultValue (false)]
- public bool FullRowSelect {
- get { return full_row_select; }
- set {
- if (full_row_select != value) {
- full_row_select = value;
- InvalidateSelection ();
- }
- }
- }
- [DefaultValue (false)]
- public bool GridLines {
- get { return grid_lines; }
- set {
- if (grid_lines != value) {
- grid_lines = value;
- this.Redraw (false);
- }
- }
- }
- [DefaultValue (ColumnHeaderStyle.Clickable)]
- public ColumnHeaderStyle HeaderStyle {
- get { return header_style; }
- set {
- if (header_style == value)
- return;
- switch (value) {
- case ColumnHeaderStyle.Clickable:
- case ColumnHeaderStyle.Nonclickable:
- case ColumnHeaderStyle.None:
- break;
- default:
- throw new InvalidEnumArgumentException (string.Format
- ("Enum argument value '{0}' is not valid for ColumnHeaderStyle", value));
- }
-
- header_style = value;
- if (view == View.Details)
- Redraw (true);
- }
- }
- [DefaultValue (true)]
- public bool HideSelection {
- get { return hide_selection; }
- set {
- if (hide_selection != value) {
- hide_selection = value;
- InvalidateSelection ();
- }
- }
- }
- [DefaultValue (false)]
- public bool HotTracking {
- get {
- return hot_tracking;
- }
- set {
- if (hot_tracking == value)
- return;
-
- hot_tracking = value;
- if (hot_tracking) {
- hover_selection = true;
- activation = ItemActivation.OneClick;
- }
- }
- }
- [DefaultValue (false)]
- public bool HoverSelection {
- get { return hover_selection; }
- set {
- if (hot_tracking && value == false)
- throw new ArgumentException ("When HotTracking is on, hover selection must be true");
- hover_selection = value;
- }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- public ListViewInsertionMark InsertionMark {
- get {
- return insertion_mark;
- }
- }
- [Editor ("System.Windows.Forms.Design.ListViewItemCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [Localizable (true)]
- [MergableProperty (false)]
- public ListViewItemCollection Items {
- get { return items; }
- }
- [DefaultValue (false)]
- public bool LabelEdit {
- get { return label_edit; }
- set {
- if (value != label_edit) {
- label_edit = value;
- // UIA Framework: Event used by Value Pattern in ListView.ListItem provider
- OnUIALabelEditChanged ();
- }
- }
- }
- [DefaultValue (true)]
- [Localizable (true)]
- public bool LabelWrap {
- get { return label_wrap; }
- set {
- if (label_wrap != value) {
- label_wrap = value;
- this.Redraw (true);
- }
- }
- }
- [DefaultValue (null)]
- public ImageList LargeImageList {
- get { return large_image_list; }
- set {
- large_image_list = value;
- this.Redraw (true);
- }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public IComparer ListViewItemSorter {
- get {
- if (View != View.SmallIcon && View != View.LargeIcon && item_sorter is ItemComparer)
- return null;
- return item_sorter;
- }
- set {
- if (item_sorter != value) {
- item_sorter = value;
- Sort ();
- }
- }
- }
- [DefaultValue (true)]
- public bool MultiSelect {
- get { return multiselect; }
- set {
- if (value != multiselect) {
- multiselect = value;
- // UIA Framework: Event used by Selection Pattern in ListView.ListItem provider
- OnUIAMultiSelectChanged ();
- }
- }
- }
- [DefaultValue(false)]
- public bool OwnerDraw {
- get { return owner_draw; }
- set {
- owner_draw = value;
- Redraw (true);
- }
- }
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public new Padding Padding {
- get {
- return base.Padding;
- }
- set {
- base.Padding = value;
- }
- }
-
- [MonoTODO ("RTL not supported")]
- [Localizable (true)]
- [DefaultValue (false)]
- public virtual bool RightToLeftLayout {
- get { return right_to_left_layout; }
- set {
- if (right_to_left_layout != value) {
- right_to_left_layout = value;
- OnRightToLeftLayoutChanged (EventArgs.Empty);
- }
- }
- }
- [DefaultValue (true)]
- public bool Scrollable {
- get { return scrollable; }
- set {
- if (scrollable != value) {
- scrollable = value;
- this.Redraw (true);
- }
- }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public SelectedIndexCollection SelectedIndices {
- get { return selected_indices; }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public SelectedListViewItemCollection SelectedItems {
- get { return selected_items; }
- }
- [DefaultValue(true)]
- public bool ShowGroups {
- get { return show_groups; }
- set {
- if (show_groups != value) {
- show_groups = value;
- Redraw(true);
- // UIA Framework: Used to update a11y Tree
- OnUIAShowGroupsChanged ();
- }
- }
- }
- [LocalizableAttribute (true)]
- [MergableProperty (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [Editor ("System.Windows.Forms.Design.ListViewGroupCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
- public ListViewGroupCollection Groups {
- get { return groups; }
- }
- [DefaultValue (false)]
- public bool ShowItemToolTips {
- get {
- return show_item_tooltips;
- }
- set {
- show_item_tooltips = value;
- item_tooltip.Active = false;
- }
- }
- [DefaultValue (null)]
- public ImageList SmallImageList {
- get { return small_image_list; }
- set {
- small_image_list = value;
- this.Redraw (true);
- }
- }
- [DefaultValue (SortOrder.None)]
- public SortOrder Sorting {
- get { return sort_order; }
- set {
- if (!Enum.IsDefined (typeof (SortOrder), value)) {
- throw new InvalidEnumArgumentException ("value", (int) value,
- typeof (SortOrder));
- }
-
- if (sort_order == value)
- return;
- sort_order = value;
- if (virtual_mode) // Sorting is not allowed in virtual mode
- return;
- if (value == SortOrder.None) {
- if (item_sorter != null) {
- // ListViewItemSorter should never be reset for SmallIcon
- // and LargeIcon view
- if (View != View.SmallIcon && View != View.LargeIcon)
- item_sorter = null;
- }
- this.Redraw (false);
- } else {
- if (item_sorter == null)
- item_sorter = new ItemComparer (value);
- if (item_sorter is ItemComparer) {
- item_sorter = new ItemComparer (value);
- }
- Sort ();
- }
- }
- }
- private void OnImageListChanged (object sender, EventArgs args)
- {
- item_control.Invalidate ();
- }
- [DefaultValue (null)]
- public ImageList StateImageList {
- get { return state_image_list; }
- set {
- if (state_image_list == value)
- return;
- if (state_image_list != null)
- state_image_list.Images.Changed -= new EventHandler (OnImageListChanged);
- state_image_list = value;
- if (state_image_list != null)
- state_image_list.Images.Changed += new EventHandler (OnImageListChanged);
- this.Redraw (true);
- }
- }
- [Bindable (false)]
- [Browsable (false)]
- [EditorBrowsable (EditorBrowsableState.Never)]
- public override string Text {
- get { return base.Text; }
- set {
- if (value == base.Text)
- return;
- base.Text = value;
- this.Redraw (true);
- }
- }
- [Browsable (true)]
- public Size TileSize {
- get {
- return tile_size;
- }
- set {
- if (value.Width <= 0 || value.Height <= 0)
- throw new ArgumentOutOfRangeException ("value");
- tile_size = value;
- if (view == View.Tile)
- Redraw (true);
- }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public ListViewItem TopItem {
- get {
- if (view == View.LargeIcon || view == View.SmallIcon || view == View.Tile)
- throw new InvalidOperationException ("Cannot get the top item in LargeIcon, SmallIcon or Tile view.");
- // there is no item
- if (this.items.Count == 0)
- return null;
- // if contents are not scrolled
- // it is the first item
- else if (h_marker == 0 && v_marker == 0)
- return this.items [0];
- // do a hit test for the scrolled position
- else {
- int header_offset = header_control.Height;
- for (int i = 0; i < items.Count; i++) {
- Point item_loc = GetItemLocation (i);
- if (item_loc.X >= 0 && item_loc.Y - header_offset >= 0)
- return items [i];
- }
- return null;
- }
- }
- set {
- if (view == View.LargeIcon || view == View.SmallIcon || view == View.Tile)
- throw new InvalidOperationException ("Cannot set the top item in LargeIcon, SmallIcon or Tile view.");
- // .Net doesn't throw any exception in the cases below
- if (value == null || value.ListView != this)
- return;
- // Take advantage this property is only valid for Details view.
- SetScrollValue (v_scroll, item_size.Height * value.Index);
- }
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- [DefaultValue (true)]
- [Browsable (false)]
- [MonoInternalNote ("Stub, not implemented")]
- public bool UseCompatibleStateImageBehavior {
- get {
- return false;
- }
- set {
- }
- }
- [DefaultValue (View.LargeIcon)]
- public View View {
- get { return view; }
- set {
- if (!Enum.IsDefined (typeof (View), value))
- throw new InvalidEnumArgumentException ("value", (int) value,
- typeof (View));
- if (view != value) {
- if (CheckBoxes && value == View.Tile)
- throw new NotSupportedException ("CheckBoxes are not"
- + " supported in Tile view. Choose a different"
- + " view or set CheckBoxes to false.");
- if (VirtualMode && value == View.Tile)
- throw new NotSupportedException ("VirtualMode is"
- + " not supported in Tile view. Choose a different"
- + " view or set ViewMode to false.");
- h_scroll.Value = v_scroll.Value = 0;
- view = value;
- Redraw (true);
- // UIA Framework: Event used to update UIA Tree.
- OnUIAViewChanged ();
- }
- }
- }
- [DefaultValue (false)]
- [RefreshProperties (RefreshProperties.Repaint)]
- public bool VirtualMode {
- get {
- return virtual_mode;
- }
- set {
- if (virtual_mode == value)
- return;
- if (!virtual_mode && items.Count > 0)
- throw new InvalidOperationException ();
- if (value && view == View.Tile)
- throw new NotSupportedException ("VirtualMode is"
- + " not supported in Tile view. Choose a different"
- + " view or set ViewMode to false.");
- virtual_mode = value;
- Redraw (true);
- }
- }
- [DefaultValue (0)]
- [RefreshProperties (RefreshProperties.Repaint)]
- public int VirtualListSize {
- get {
- return virtual_list_size;
- }
- set {
- if (value < 0)
- throw new ArgumentException ("value");
- if (virtual_list_size == value)
- return;
- virtual_list_size = value;
- if (virtual_mode) {
- selected_indices.Reset ();
- Redraw (true);
- }
- }
- }
- #endregion // Public Instance Properties
- #region Internal Methods Properties
-
- internal int FirstVisibleIndex {
- get {
- // there is no item
- if (this.items.Count == 0)
- return 0;
-
- if (h_marker == 0 && v_marker == 0)
- return 0;
-
- Size item_size = ItemSize;
- // In virtual mode we always have fixed positions, and we can infer the positon easily
- if (virtual_mode) {
- int first = 0;
- switch (view) {
- case View.Details:
- first = v_marker / item_size.Height;
- break;
- case View.LargeIcon:
- case View.SmallIcon:
- first = (v_marker / (item_size.Height + y_spacing)) * cols;
- break;
- case View.List:
- first = (h_marker / (item_size.Width * x_spacing)) * rows;
- break;
- }
- if (first >= items.Count)
- first = items.Count;
- return first;
- }
- for (int i = 0; i < items.Count; i++) {
- Rectangle item_rect = new Rectangle (GetItemLocation (i), item_size);
- if (item_rect.Right >= 0 && item_rect.Bottom >= 0)
- return i;
- }
- return 0;
- }
- }
-
- internal int LastVisibleIndex {
- get {
- for (int i = FirstVisibleIndex; i < Items.Count; i++) {
- if (View == View.List || Alignment == ListViewAlignment.Left) {
- if (GetItemLocation (i).X > item_control.ClientRectangle.Right)
- return i - 1;
- } else {
- if (GetItemLocation (i).Y > item_control.ClientRectangle.Bottom)
- return i - 1;
- }
- }
-
- return Items.Count - 1;
- }
- }
- internal void OnSelectedIndexChanged ()
- {
- if (is_selection_available)
- OnSelectedIndexChanged (EventArgs.Empty);
- }
- internal int TotalWidth {
- get { return Math.Max (this.Width, this.layout_wd); }
- }
- internal int TotalHeight {
- get { return Math.Max (this.Height, this.layout_ht); }
- }
- internal void Redraw (bool recalculate)
- {
- // Avoid calculations when control is being updated
- if (updating)
- return;
- // VirtualMode doesn't do any calculations until handle is created
- if (virtual_mode && !IsHandleCreated)
- return;
- if (recalculate)
- CalculateListView (this.alignment);
- Invalidate (true);
- }
- void InvalidateSelection ()
- {
- foreach (int selected_index in SelectedIndices)
- items [selected_index].Invalidate ();
- }
- const int text_padding = 15;
- internal Size GetChildColumnSize (int index)
- {
- Size ret_size = Size.Empty;
- ColumnHeader col = this.columns [index];
- if (col.Width == -2) { // autosize = max(items, columnheader)
- Size size = Size.Ceiling (TextRenderer.MeasureString
- (col.Text, this.Font));
- size.Width += text_padding;
- ret_size = BiggestItem (index);
- if (size.Width > ret_size.Width)
- ret_size = size;
- }
- else { // -1 and all the values < -2 are put under one category
- ret_size = BiggestItem (index);
- // fall back to empty columns' width if no subitem is available for a column
- if (ret_size.IsEmpty) {
- ret_size.Width = ThemeEngine.Current.ListViewEmptyColumnWidth;
- if (col.Text.Length > 0)
- ret_size.Height = Size.Ceiling (TextRenderer.MeasureString
- (col.Text, this.Font)).Height;
- else
- ret_size.Height = this.Font.Height;
- }
- }
- ret_size.Height += text_padding;
- // adjust the size for icon and checkbox for 0th column
- if (index == 0) {
- ret_size.Width += (this.CheckBoxSize.Width + 4);
- if (this.small_image_list != null)
- ret_size.Width += this.small_image_list.ImageSize.Width;
- }
- return ret_size;
- }
- // Returns the size of biggest item text in a column
- // or the sum of the text and indent count if we are on 2.0
- private Size BiggestItem (int col)
- {
- Size temp = Size.Empty;
- Size ret_size = Size.Empty;
- bool use_indent_count = small_image_list != null;
- // VirtualMode uses the first item text size
- if (virtual_mode && items.Count > 0) {
- ListViewItem item = items [0];
- ret_size = Size.Ceiling (TextRenderer.MeasureString (item.SubItems[col].Text,
- Font));
- if (use_indent_count)
- ret_size.Width += item.IndentCount * small_image_list.ImageSize.Width;
- } else {
- // 0th column holds the item text, we check the size of
- // the various subitems falling in that column and get
- // the biggest one's size.
- foreach (ListViewItem item in items) {
- if (col >= item.SubItems.Count)
- continue;
- temp = Size.Ceiling (TextRenderer.MeasureString
- (item.SubItems [col].Text, Font));
- if (use_indent_count)
- temp.Width += item.IndentCount * small_image_list.ImageSize.Width;
-
- if (temp.Width > ret_size.Width)
- ret_size = temp;
- }
- }
- // adjustment for space in Details view
- if (!ret_size.IsEmpty && view == View.Details)
- ret_size.Width += ThemeEngine.Current.ListViewItemPaddingWidth;
- return ret_size;
- }
- const int max_wrap_padding = 30;
- // Sets the size of the biggest item text as per the view
- private void CalcTextSize ()
- {
- // clear the old value
- text_size = Size.Empty;
- if (items.Count == 0)
- return;
- text_size = BiggestItem (0);
- if (view == View.LargeIcon && this.label_wrap) {
- Size temp = Size.Empty;
- if (this.check_boxes)
- temp.Width += 2 * this.CheckBoxSize.Width;
- int icon_w = LargeImageList == null ? 12 : LargeImageList.ImageSize.Width;
- temp.Width += icon_w + max_wrap_padding;
- // wrapping is done for two lines only
- if (text_size.Width > temp.Width) {
- text_size.Width = temp.Width;
- text_size.Height *= 2;
- }
- }
- else if (view == View.List) {
- // in list view max text shown in determined by the
- // control width, even if scolling is enabled.
- int max_wd = this.Width - (this.CheckBoxSize.Width - 2);
- if (this.small_image_list != null)
- max_wd -= this.small_image_list.ImageSize.Width;
- if (text_size.Width > max_wd)
- text_size.Width = max_wd;
- }
- // we do the default settings, if we have got 0's
- if (text_size.Height <= 0)
- text_size.Height = this.Font.Height;
- if (text_size.Width <= 0)
- text_size.Width = this.Width;
- // little adjustment
- text_size.Width += 2;
- text_size.Height += 2;
- }
- private void SetScrollValue (ScrollBar scrollbar, int val)
- {
- int max;
- if (scrollbar == h_scroll)
- max = h_scroll.Maximum - h_scroll.LargeChange + 1;
- else
- max = v_scroll.Maximum - v_scroll.LargeChange + 1;
- if (val > max)
- val = max;
- else if (val < scrollbar.Minimum)
- val = scrollbar.Minimum;
- scrollbar.Value = val;
- }
- private void Scroll (ScrollBar scrollbar, int delta)
- {
- if (delta == 0 || !scrollbar.Visible)
- return;
- SetScrollValue (scrollbar, scrollbar.Value + delta);
- }
- private void CalculateScrollBars ()
- {
- Rectangle client_area = ClientRectangle;
- int height = client_area.Height;
- int width = client_area.Width;
- Size item_size;
-
- if (!scrollable) {
- h_scroll.Visible = false;
- v_scroll.Visible = false;
- item_control.Size = new Size (width, height);
- header_control.Width = width;
- return;
- }
- // Don't calculate if the view is not displayable
- if (client_area.Height < 0 || client_area.Width < 0)
- return;
- // making a scroll bar visible might make
- // other scroll bar visible
- if (layout_wd > client_area.Right) {
- h_scroll.Visible = true;
- if ((layout_ht + h_scroll.Height) > client_area.Bottom)
- v_scroll.Visible = true;
- else
- v_scroll.Visible = false;
- } else if (layout_ht > client_area.Bottom) {
- v_scroll.Visible = true;
- if ((layout_wd + v_scroll.Width) > client_area.Right)
- h_scroll.Visible = true;
- else
- h_scroll.Visible = false;
- } else {
- h_scroll.Visible = false;
- v_scroll.Visible = false;
- }
- item_size = ItemSize;
- if (h_scroll.is_visible) {
- h_scroll.Location = new Point (client_area.X, client_area.Bottom - h_scroll.Height);
- h_scroll.Minimum = 0;
- // if v_scroll is visible, adjust the maximum of the
- // h_scroll to account for the width of v_scroll
- if (v_scroll.Visible) {
- h_scroll.Maximum = layout_wd + v_scroll.Width;
- h_scroll.Width = client_area.Width - v_scroll.Width;
- }
- else {
- h_scroll.Maximum = layout_wd;
- h_scroll.Width = client_area.Width;
- }
- if (view == View.List)
- h_scroll.SmallChange = item_size.Width + ThemeEngine.Current.ListViewHorizontalSpacing;
- else
- h_scroll.SmallChange = Font.Height;
- h_scroll.LargeChange = client_area.Width;
- height -= h_scroll.Height;
- }
- if (v_scroll.is_visible) {
- v_scroll.Location = new Point (client_area.Right - v_scroll.Width, client_area.Y);
- v_scroll.Minimum = 0;
- // if h_scroll is visible, adjust the height of
- // v_scroll to account for the height of h_scroll
- if (h_scroll.Visible) {
- v_scroll.Maximum = layout_ht + h_scroll.Height;
- v_scroll.Height = client_area.Height > h_scroll.Height ? client_area.Height - h_scroll.Height : 0;
- } else {
- v_scroll.Maximum = layout_ht;
- v_scroll.Height = client_area.Height;
- }
- if (view == View.Details) {
- // Need to update Maximum if using LargeChange with value other than the visible area
- int headerPlusOneItem = header_control.Height + item_size.Height;
- v_scroll.LargeChange = v_scroll.Height > headerPlusOneItem ? v_scroll.Height - headerPlusOneItem : 0;
- v_scroll.Maximum = v_scroll.Maximum > headerPlusOneItem ? v_scroll.Maximum - headerPlusOneItem : 0;
- } else
- v_scroll.LargeChange = v_scroll.Height;
- v_scroll.SmallChange = item_size.Height;
- width -= v_scroll.Width;
- }
-
- item_control.Size = new Size (width, height);
- if (header_control.is_visible)
- header_control.Width = width;
- }
- internal int GetReorderedColumnIndex (ColumnHeader column)
- {
- if (reordered_column_indices == null)
- return column.Index;
- for (int i = 0; i < Columns.Count; i++)
- if (reordered_column_indices [i] == column.Index)
- return i;
- return -1;
- }
- internal ColumnHeader GetReorderedColumn (int index)
- {
- if (reordered_column_indices == null)
- return Columns [index];
- else
- return Columns [reordered_column_indices [index]];
- }
- internal void ReorderColumn (ColumnHeader col, int index, bool fireEvent)
- {
- if (fireEvent) {
- ColumnReorderedEventHandler eh = (ColumnReorderedEventHandler) (Events [ColumnReorderedEvent]);
- if (eh != null){
- ColumnReorderedEventArgs args = new ColumnReorderedEventArgs (col.Index, index, col);
- eh (this, args);
- if (args.Cancel) {
- header_control.Invalidate ();
- item_control.Invalidate ();
- return;
- }
- }
- }
- int column_count = Columns.Count;
- if (reordered_column_indices == null) {
- reordered_column_indices = new int [column_count];
- for (int i = 0; i < column_count; i++)
- reordered_column_indices [i] = i;
- }
- if (reordered_column_indices [index] == col.Index)
- return;
- int[] curr = reordered_column_indices;
- int [] result = new int [column_count];
- int curr_idx = 0;
- for (int i = 0; i < column_count; i++) {
- if (curr_idx < column_count && curr [curr_idx] == col.Index)
- curr_idx++;
- if (i == index)
- result [i] = col.Index;
- else
- result [i] = curr [curr_idx++];
- }
- ReorderColumns (result, true);
- }
- internal void ReorderColumns (int [] display_indices, bool redraw)
- {
- reordered_column_indices = display_indices;
- for (int i = 0; i < Columns.Count; i++) {
- ColumnHeader col = Columns [i];
- col.InternalDisplayIndex = reordered_column_indices [i];
- }
- if (redraw && view == View.Details && IsHandleCreated) {
- LayoutDetails ();
- header_control.Invalidate ();
- item_control.Invalidate ();
- }
- }
- internal void AddColumn (ColumnHeader newCol, int index, bool redraw)
- {
- int column_count = Columns.Count;
- newCol.SetListView (this);
- int [] display_indices = new int [column_count];
- for (int i = 0; i < column_count; i++) {
- ColumnHeader col = Columns [i];
- if (i == index) {
- display_indices [i] = index;
- } else {
- int display_index = col.InternalDisplayIndex;
- if (display_index < index) {
- display_indices [i] = display_index;
- } else {
- display_indices [i] = (display_index + 1);
- }
- }
- }
- ReorderColumns (display_indices, redraw);
- Invalidate ();
- }
- Size LargeIconItemSize
- {
- get {
- int image_w = LargeImageList == null ? 12 : LargeImageList.ImageSize.Width;
- int image_h = LargeImageList == null ? 2 : LargeImageList.ImageSize.Height;
- int h = text_size.Height + 2 + Math.Max (CheckBoxSize.Height, image_h);
- int w = Math.Max (text_size.Width, image_w);
- if (check_boxes)
- w += 2 + CheckBoxSize.Width;
- return new Size (w, h);
- }
- }
- Size SmallIconItemSize {
- get {
- int image_w = SmallImageList == null ? 0 : SmallImageList.ImageSize.Width;
- int image_h = SmallImageList == null ? 0 : SmallImageList.ImageSize.Height;
- int h = Math.Max (text_size.Height, Math.Max (CheckBoxSize.Height, image_h));
- int w = text_size.Width + image_w;
- if (check_boxes)
- w += 2 + CheckBoxSize.Width;
- return new Size (w, h);
- }
- }
- Size TileItemSize {
- get {
- // Calculate tile size if needed
- // It appears that using Font.Size instead of a SizeF value can give us
- // a slightly better approach to the proportions defined in .Net
- if (tile_size == Size.Empty) {
- int image_w = LargeImageList == null ? 0 : LargeImageList.ImageSize.Width;
- int image_h = LargeImageList == null ? 0 : LargeImageList.ImageSize.Height;
- int w = (int)Font.Size * ThemeEngine.Current.ListViewTileWidthFactor + image_w + 4;
- int h = Math.Max ((int)Font.Size * ThemeEngine.Current.ListViewTileHeightFactor, image_h);
-
- tile_size = new Size (w, h);
- }
-
- return tile_size;
- }
- }
- int GetDetailsItemHeight ()
- {
- int item_height;
- int checkbox_height = CheckBoxes ? CheckBoxSize.Height : 0;
- int small_image_height = SmallImageList == null ? 0 : SmallImageList.ImageSize.Height;
- item_height = Math.Max (checkbox_height, text_size.Height);
- item_height = Math.Max (item_height, small_image_height);
- return item_height;
- }
- void SetItemLocation (int index, int x, int y, int row, int col)
- {
- Point old_location = items_location [index];
- if (old_location.X == x && old_location.Y == y)
- return;
- items_location [index] = new Point (x, y);
- items_matrix_location [index] = new ItemMatrixLocation (row, col);
- //
- // Initial position matches item's position in ListViewItemCollection
- //
- reordered_items_indices [index] = index;
- }
- void ShiftItemsPositions (int from, int to, bool forward)
- {
- if (forward) {
- for (int i = to + 1; i > from; i--) {
- reordered_items_indices [i] = reordered_items_indices [i - 1];
- ListViewItem item = items [reordered_items_indices [i]];
- item.Invalidate ();
- item.DisplayIndex = i;
- item.Invalidate ();
- }
- } else {
- for (int i = from - 1; i < to; i++) {
- reordered_items_indices [i] = reordered_items_indices [i + 1];
- ListViewItem item = items [reordered_items_indices [i]];
- item.Invalidate ();
- item.DisplayIndex = i;
- item.Invalidate ();
- }
- }
- }
- internal void ChangeItemLocation (int display_index, Point new_pos)
- {
- int new_display_index = GetDisplayIndexFromLocation (new_pos);
- if (new_display_index == display_index)
- return;
- int item_index = reordered_items_indices [display_index];
- ListViewItem item = items [item_index];
- bool forward = new_display_index < display_index;
- int index_from, index_to;
- if (forward) {
- index_from = new_display_index;
- index_to = display_index - 1;
- } else {
- index_from = display_index + 1;
- index_to = new_display_index;
- }
- ShiftItemsPositions (index_from, index_to, forward);
- reordered_items_indices [new_display_index] = item_index;
- item.Invalidate ();
- item.DisplayIndex = new_display_index;
- item.Invalidate ();
- }
- int GetDisplayIndexFromLocation (Point loc)
- {
- int display_index = -1;
- Rectangle item_area;
- // First item
- if (loc.X < 0 || loc.Y < 0)
- return 0;
- // Adjustment to put in the next position refered by 'loc'
- loc.X -= item_size.Width / 2;
- if (loc.X < 0)
- loc.X = 0;
- for (int i = 0; i < items.Count; i++) {
- item_area = new Rectangle (GetItemLocation (i), item_size);
- item_area.Inflate (ThemeEngine.Current.ListViewHorizontalSpacing,
- ThemeEngine.Current.ListViewVerticalSpacing);
- if (item_area.Contains (loc)) {
- display_index = i;
- break;
- }
- }
- // Put in in last position
- if (display_index == -1)
- display_index = items.Count - 1;
- return display_index;
- }
- // When using groups, the items with no group assigned
- // belong to the DefaultGroup
- int GetDefaultGroupItems ()
- {
- int count = 0;
- foreach (ListViewItem item in items)
- if (item.Group == null)
- count++;
- return count;
- }
- // cache the spacing to let virtualmode compute the positions on the fly
- int x_spacing;
- int y_spacing;
- int rows;
- int cols;
- int[,] item_index_matrix;
- void CalculateRowsAndCols (Size item_size, bool left_aligned, int x_spacing, int y_spacing)
- {
- Rectangle area = ClientRectangle;
- if (UseCustomColumnWidth)
- CalculateCustomColumnWidth ();
- if (UsingGroups) {
- // When groups are used the alignment is always top-aligned
- rows = 0;
- cols = 0;
- int items = 0;
- groups.DefaultGroup.ItemCount = GetDefaultGroupItems ();
- for (int i = 0; i < groups.InternalCount; i++) {
- ListViewGroup group = groups.GetInternalGroup (i);
- int items_in_group = group.GetActualItemCount ();
- if (items_in_group == 0)
- continue;
- int group_cols = (int) Math.Floor ((double)(area.Width - v_scroll.Width + x_spacing) / (double)(item_size.Width + x_spacing));
- if (group_cols <= 0)
- group_cols = 1;
- int group_rows = (int) Math.Ceiling ((double)items_in_group / (double)group_cols);
- group.starting_row = rows;
- group.rows = group_rows;
- group.starting_item = items;
- group.current_item = 0; // Reset layout
- cols = Math.Max (group_cols, cols);
- rows += group_rows;
- items += items_in_group;
- }
- } else
- {
- // Simple matrix if no groups are used
- if (left_aligned) {
- rows = (int) Math.Floor ((double)(area.Height - h_scroll.Height + y_spacing) / (double)(item_size.Height + y_spacing));
- if (rows <= 0)
- rows = 1;
- cols = (int) Math.Ceiling ((double)items.Count / (double)rows);
- } else {
- if (UseCustomColumnWidth)
- cols = (int) Math.Floor ((double)(area.Width - v_scroll.Width) / (double)(custom_column_width));
- else
- cols = (int) Math.Floor ((double)(area.Width - v_scroll.Width + x_spacing) / (double)(item_size.Width + x_spacing));
- if (cols < 1)
- cols = 1;
- rows = (int) Math.Ceiling ((double)items.Count / (double)cols);
- }
- }
- item_index_matrix = new int [rows, cols];
- }
- // When using custom column width, we look for the minimum one
- void CalculateCustomColumnWidth ()
- {
- int min_width = Int32.MaxValue;
- for (int i = 0; i < columns.Count; i++) {
- int col_width = columns [i].Width;
- if (col_width < min_width)
- min_width = col_width;
- }
- custom_column_width = min_width;
- }
- void LayoutIcons (Size item_size, bool left_aligned, int x_spacing, int y_spacing)
- {
- header_control.Visible = false;
- header_control.Size = Size.Empty;
- item_control.Visible = true;
- item_control.Location = Point.Empty;
- ItemSize = item_size; // Cache item size
- this.x_spacing = x_spacing;
- this.y_spacing = y_spacing;
- if (items.Count == 0)
- return;
- Size sz = item_size;
- CalculateRowsAndCols (sz, left_aligned, x_spacing, y_spacing);
- layout_wd = UseCustomColumnWidth ? cols * custom_column_width : cols * (sz.Width + x_spacing) - x_spacing;
- layout_ht = rows * (sz.Height + y_spacing) - y_spacing;
- if (virtual_mode) { // no actual assignment is needed on items for virtual mode
- item_control.Size = new Size (layout_wd, layout_ht)…
Large files files are truncated, but you can click here to view the full file