From e58e33974a31cc0903ca92e4a99431ca5d6d7fe6 Mon Sep 17 00:00:00 2001 From: Dimitrij Date: Thu, 29 May 2025 18:49:20 +0100 Subject: [PATCH] cosmetic changes --- ObjectListView/ObjectListView.cs | 3196 +++++++++++------ ObjectListView/Rendering/Renderers.cs | 8 +- ObjectListView/TreeListView.cs | 4 +- .../Utilities/ColumnSelectionForm.Designer.cs | 2 +- ObjectListView/VirtualObjectListView.cs | 4 +- 5 files changed, 2118 insertions(+), 1096 deletions(-) diff --git a/ObjectListView/ObjectListView.cs b/ObjectListView/ObjectListView.cs index 16abde5d..e14caa19 100644 --- a/ObjectListView/ObjectListView.cs +++ b/ObjectListView/ObjectListView.cs @@ -1,3 +1,4 @@ +#region File Header and Changelog /* * ObjectListView - A listview to show various aspects of a collection of objects * @@ -569,6 +570,7 @@ * * If you wish to use this code in a closed source application, please contact phillip.piper@gmail.com. */ +#endregion using System; using System.Collections; @@ -580,16 +582,19 @@ using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.InteropServices; +using System.Runtime.Serialization.Formatters; using System.Runtime.Serialization.Formatters.Binary; +using System.Runtime.Versioning; +using System.Threading; using System.Windows.Forms; using System.Windows.Forms.VisualStyles; -using System.Runtime.Serialization.Formatters; -using System.Threading; using MethodInvoker = System.Windows.Forms.MethodInvoker; namespace BrightIdeasSoftware { + [SupportedOSPlatform("windows")] + #region about ObjectListView /// /// An ObjectListView is a much easier to use, and much more powerful, version of the ListView. /// @@ -641,15 +646,19 @@ namespace BrightIdeasSoftware /// System.Windows.Forms (obviously) /// /// - [Designer(typeof(BrightIdeasSoftware.Design.ObjectListViewDesigner))] - public partial class ObjectListView : ListView, ISupportInitialize { - + /// + #endregion + [Designer(typeof(BrightIdeasSoftware.Design.ObjectListViewDesigner))] + public partial class ObjectListView : ListView, ISupportInitialize + { + #region Life and death - + /// /// Create an ObjectListView /// - public ObjectListView() { + public ObjectListView() + { this.ColumnClick += new ColumnClickEventHandler(this.HandleColumnClick); this.Layout += new LayoutEventHandler(this.HandleLayout); this.ColumnWidthChanging += new ColumnWidthChangingEventHandler(this.HandleColumnWidthChanging); @@ -660,27 +669,29 @@ namespace BrightIdeasSoftware // Turn on owner draw so that we are responsible for our own fates (and isolated from bugs in the underlying ListView) this.OwnerDraw = true; -// ReSharper disable DoNotCallOverridableMethodsInConstructor + // ReSharper disable DoNotCallOverridableMethodsInConstructor this.DoubleBuffered = true; // kill nasty flickers. hiss... me hates 'em this.ShowSortIndicators = true; // Setup the overlays that will be controlled by the IDE settings this.InitializeStandardOverlays(); this.InitializeEmptyListMsgOverlay(); -// ReSharper restore DoNotCallOverridableMethodsInConstructor + // ReSharper restore DoNotCallOverridableMethodsInConstructor } /// /// Dispose of any resources this instance has been using /// /// - protected override void Dispose(bool disposing) { + protected override void Dispose(bool disposing) + { base.Dispose(disposing); - if (!disposing) + if (!disposing) return; - foreach (GlassPanelForm glassPanel in this.glassPanels) { + foreach (GlassPanelForm glassPanel in this.glassPanels) + { glassPanel.Unbind(); glassPanel.Dispose(); } @@ -702,15 +713,18 @@ namespace BrightIdeasSoftware /// /// Gets whether or not the left mouse button is down at this very instant /// - public static bool IsLeftMouseDown { + public static bool IsLeftMouseDown + { get { return (Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left; } } /// /// Gets whether the program running on Vista or later? /// - static public bool IsVistaOrLater { - get { + static public bool IsVistaOrLater + { + get + { if (!ObjectListView.sIsVistaOrLater.HasValue) ObjectListView.sIsVistaOrLater = Environment.OSVersion.Version.Major >= 6; return ObjectListView.sIsVistaOrLater.Value; @@ -721,9 +735,12 @@ namespace BrightIdeasSoftware /// /// Gets whether the program running on Win7 or later? /// - static public bool IsWin7OrLater { - get { - if (!ObjectListView.sIsWin7OrLater.HasValue) { + static public bool IsWin7OrLater + { + get + { + if (!ObjectListView.sIsWin7OrLater.HasValue) + { // For some reason, Win7 is v6.1, not v7.0 Version version = Environment.OSVersion.Version; ObjectListView.sIsWin7OrLater = version.Major > 6 || (version.Major == 6 && version.Minor > 0); @@ -736,17 +753,23 @@ namespace BrightIdeasSoftware /// /// Gets or sets how what smoothing mode will be applied to graphic operations. /// - static public System.Drawing.Drawing2D.SmoothingMode SmoothingMode { + [Browsable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + static public System.Drawing.Drawing2D.SmoothingMode SmoothingMode + { get { return ObjectListView.sSmoothingMode; } set { ObjectListView.sSmoothingMode = value; } } - static private System.Drawing.Drawing2D.SmoothingMode sSmoothingMode = - System.Drawing.Drawing2D.SmoothingMode.HighQuality; + static private System.Drawing.Drawing2D.SmoothingMode sSmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; /// /// Gets or sets how should text be renderered. /// - static public System.Drawing.Text.TextRenderingHint TextRenderingHint { + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + /// + /// Gets or sets how should text be renderered. + /// + static public System.Drawing.Text.TextRenderingHint TextRenderingHint + { get { return ObjectListView.sTextRendereringHint; } set { ObjectListView.sTextRendereringHint = value; } } @@ -757,10 +780,17 @@ namespace BrightIdeasSoftware /// Gets or sets the string that will be used to title groups when the group key is null. /// Exposed so it can be localized. /// - static public string GroupTitleDefault { + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + /// + /// Gets or sets the string that will be used to title groups when the group key is null. + /// Exposed so it can be localized. + /// + static public string GroupTitleDefault + { get { return ObjectListView.sGroupTitleDefault; } set { ObjectListView.sGroupTitleDefault = value ?? "{null}"; } - }static private string sGroupTitleDefault = "{null}"; + } + static private string sGroupTitleDefault = "{null}"; /// /// Convert the given enumerable into an ArrayList as efficiently as possible @@ -772,11 +802,13 @@ namespace BrightIdeasSoftware /// /// When we move to .NET 3.5, we can use LINQ and not need this method. /// - public static ArrayList EnumerableToArray(IEnumerable collection, bool alwaysCreate) { + public static ArrayList EnumerableToArray(IEnumerable collection, bool alwaysCreate) + { if (collection == null) return new ArrayList(); - if (!alwaysCreate) { + if (!alwaysCreate) + { ArrayList array = collection as ArrayList; if (array != null) return array; @@ -803,7 +835,8 @@ namespace BrightIdeasSoftware /// /// /// When we move to .NET 3.5, we can use LINQ and not need this method. - public static int EnumerableCount(IEnumerable collection) { + public static int EnumerableCount(IEnumerable collection) + { if (collection == null) return 0; @@ -812,7 +845,7 @@ namespace BrightIdeasSoftware return iCollection.Count; int i = 0; -// ReSharper disable once UnusedVariable + // ReSharper disable once UnusedVariable foreach (object x in collection) i++; return i; @@ -827,7 +860,8 @@ namespace BrightIdeasSoftware /// /// When we move to .NET 3.5, we can use LINQ and not need this method. /// - public static bool IsEnumerableEmpty(IEnumerable collection) { + public static bool IsEnumerableEmpty(IEnumerable collection) + { return collection == null || (collection is string) || !collection.GetEnumerator().MoveNext(); } @@ -846,7 +880,24 @@ namespace BrightIdeasSoftware /// Be warned: if you set this to true, it can be very difficult to track down /// typing mistakes or name changes in AspectNames. /// - public static bool IgnoreMissingAspects { + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + /// + /// Gets or sets whether all ObjectListViews will silently ignore missing aspect errors. + /// + /// + /// + /// By default, if an ObjectListView is asked to display an aspect + /// (i.e. a field/property/method) + /// that does not exist from a model, it displays an error message in that cell, since that + /// condition is normally a programming error. There are some use cases where + /// this is not an error -- in those cases, set this to true and ObjectListView will + /// simply display an empty cell. + /// + /// Be warned: if you set this to true, it can be very difficult to track down + /// typing mistakes or name changes in AspectNames. + /// + public static bool IgnoreMissingAspects + { get { return Munger.IgnoreMissingAspects; } set { Munger.IgnoreMissingAspects = value; } } @@ -860,18 +911,32 @@ namespace BrightIdeasSoftware /// /// As with all cell padding, this setting only takes effect when the control is owner drawn. /// - public static bool ShowCellPaddingBounds { - get { return sShowCellPaddingBounds; } - set { sShowCellPaddingBounds = value; } + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + /// + /// Gets or sets whether the control will draw a rectangle in each cell showing the cell padding. + /// + /// + /// + /// This can help with debugging display problems from cell padding. + /// + /// As with all cell padding, this setting only takes effect when the control is owner drawn. + /// + public static bool ShowCellPaddingBounds + { + get { return sShowCellPaddingBounds; } + set { sShowCellPaddingBounds = value; } } private static bool sShowCellPaddingBounds; /// /// Gets the style that will be used by default to format disabled rows /// - public static SimpleItemStyle DefaultDisabledItemStyle { - get { - if (sDefaultDisabledItemStyle == null) { + public static SimpleItemStyle DefaultDisabledItemStyle + { + get + { + if (sDefaultDisabledItemStyle == null) + { sDefaultDisabledItemStyle = new SimpleItemStyle(); sDefaultDisabledItemStyle.ForeColor = Color.DarkGray; } @@ -883,9 +948,12 @@ namespace BrightIdeasSoftware /// /// Gets the style that will be used by default to format hot rows /// - public static HotItemStyle DefaultHotItemStyle { - get { - if (sDefaultHotItemStyle == null) { + public static HotItemStyle DefaultHotItemStyle + { + get + { + if (sDefaultHotItemStyle == null) + { sDefaultHotItemStyle = new HotItemStyle(); sDefaultHotItemStyle.BackColor = Color.FromArgb(224, 235, 253); } @@ -933,7 +1001,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] - public virtual List AllColumns { + public virtual List AllColumns + { get { return this.allColumns; } set { this.allColumns = value ?? new List(); } } @@ -945,7 +1014,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("If using alternate colors, what color should the background of alterate rows be?"), DefaultValue(typeof(Color), "")] - public Color AlternateRowBackColor { + public Color AlternateRowBackColor + { get { return alternateRowBackColor; } set { alternateRowBackColor = value; } } @@ -955,8 +1025,10 @@ namespace BrightIdeasSoftware /// Gets the alternate row background color that has been set, or the default color /// [Browsable(false)] - public virtual Color AlternateRowBackColorOrDefault { - get { + public virtual Color AlternateRowBackColorOrDefault + { + get + { return this.alternateRowBackColor == Color.Empty ? Color.LemonChiffon : this.alternateRowBackColor; } } @@ -966,7 +1038,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual OLVColumn AlwaysGroupByColumn { + public virtual OLVColumn AlwaysGroupByColumn + { get { return alwaysGroupByColumn; } set { alwaysGroupByColumn = value; } } @@ -979,7 +1052,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual SortOrder AlwaysGroupBySortOrder { + public virtual SortOrder AlwaysGroupBySortOrder + { get { return alwaysGroupBySortOrder; } set { alwaysGroupBySortOrder = value; } } @@ -994,7 +1068,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual ImageList BaseSmallImageList { + public virtual ImageList BaseSmallImageList + { get { return base.SmallImageList; } set { base.SmallImageList = value; } } @@ -1007,9 +1082,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("How does the user indicate that they want to edit a cell?"), DefaultValue(CellEditActivateMode.None)] - public virtual CellEditActivateMode CellEditActivation { + public virtual CellEditActivateMode CellEditActivation + { get { return cellEditActivation; } - set { + set + { cellEditActivation = value; if (this.Created) this.Invalidate(); @@ -1037,7 +1114,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("When a cell is edited, should the whole cell be used?"), DefaultValue(true)] - public virtual bool CellEditUseWholeCell { + public virtual bool CellEditUseWholeCell + { get { return cellEditUseWholeCell; } set { cellEditUseWholeCell = value; } } @@ -1049,7 +1127,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public CellEditKeyEngine CellEditKeyEngine { + public CellEditKeyEngine CellEditKeyEngine + { get { return this.cellEditKeyEngine ?? (this.cellEditKeyEngine = new CellEditKeyEngine()); } set { this.cellEditKeyEngine = value; } } @@ -1060,8 +1139,10 @@ namespace BrightIdeasSoftware /// /// This will obviously be null if no cell is being edited. [Browsable(false)] - public Control CellEditor { - get { + public Control CellEditor + { + get + { return this.cellEditor; } } @@ -1076,14 +1157,19 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should Tab/Shift-Tab change rows while cell editing?"), DefaultValue(false)] - public virtual bool CellEditTabChangesRows { + public virtual bool CellEditTabChangesRows + { get { return cellEditTabChangesRows; } - set { + set + { cellEditTabChangesRows = value; - if (cellEditTabChangesRows) { + if (cellEditTabChangesRows) + { this.CellEditKeyEngine.SetKeyBehaviour(Keys.Tab, CellEditCharacterBehaviour.ChangeColumnRight, CellEditAtEdgeBehaviour.ChangeRow); - this.CellEditKeyEngine.SetKeyBehaviour(Keys.Tab|Keys.Shift, CellEditCharacterBehaviour.ChangeColumnLeft, CellEditAtEdgeBehaviour.ChangeRow); - } else { + this.CellEditKeyEngine.SetKeyBehaviour(Keys.Tab | Keys.Shift, CellEditCharacterBehaviour.ChangeColumnLeft, CellEditAtEdgeBehaviour.ChangeRow); + } + else + { this.CellEditKeyEngine.SetKeyBehaviour(Keys.Tab, CellEditCharacterBehaviour.ChangeColumnRight, CellEditAtEdgeBehaviour.Wrap); this.CellEditKeyEngine.SetKeyBehaviour(Keys.Tab | Keys.Shift, CellEditCharacterBehaviour.ChangeColumnLeft, CellEditAtEdgeBehaviour.Wrap); } @@ -1100,14 +1186,19 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should Enter change rows while cell editing?"), DefaultValue(false)] - public virtual bool CellEditEnterChangesRows { + public virtual bool CellEditEnterChangesRows + { get { return cellEditEnterChangesRows; } - set { + set + { cellEditEnterChangesRows = value; - if (cellEditEnterChangesRows) { + if (cellEditEnterChangesRows) + { this.CellEditKeyEngine.SetKeyBehaviour(Keys.Enter, CellEditCharacterBehaviour.ChangeRowDown, CellEditAtEdgeBehaviour.ChangeColumn); this.CellEditKeyEngine.SetKeyBehaviour(Keys.Enter | Keys.Shift, CellEditCharacterBehaviour.ChangeRowUp, CellEditAtEdgeBehaviour.ChangeColumn); - } else { + } + else + { this.CellEditKeyEngine.SetKeyBehaviour(Keys.Enter, CellEditCharacterBehaviour.EndEdit, CellEditAtEdgeBehaviour.EndEdit); this.CellEditKeyEngine.SetKeyBehaviour(Keys.Enter | Keys.Shift, CellEditCharacterBehaviour.EndEdit, CellEditAtEdgeBehaviour.EndEdit); } @@ -1119,9 +1210,12 @@ namespace BrightIdeasSoftware /// Gets the tool tip control that shows tips for the cells /// [Browsable(false)] - public ToolTipControl CellToolTip { - get { - if (this.cellToolTip == null) { + public ToolTipControl CellToolTip + { + get + { + if (this.cellToolTip == null) + { this.CreateCellToolTip(); } return this.cellToolTip; @@ -1154,7 +1248,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("How much padding will be applied to each cell in this control?"), DefaultValue(null)] - public Rectangle? CellPadding { + public Rectangle? CellPadding + { get { return this.cellPadding; } set { this.cellPadding = value; } } @@ -1168,41 +1263,46 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("How will cell values be vertically aligned?"), DefaultValue(StringAlignment.Center)] - public virtual StringAlignment CellVerticalAlignment { - get { return this.cellVerticalAlignment; } - set { this.cellVerticalAlignment = value; } + public virtual StringAlignment CellVerticalAlignment + { + get { return this.cellVerticalAlignment; } + set { this.cellVerticalAlignment = value; } } private StringAlignment cellVerticalAlignment = StringAlignment.Center; /// /// Should this list show checkboxes? /// - public new bool CheckBoxes { - get { return base.CheckBoxes; } - set { - // Due to code in the base ListView class, turning off CheckBoxes on a virtual - // list always throws an InvalidOperationException. We have to do some major hacking - // to get around that - if (this.VirtualMode) { - // Leave virtual mode - this.StateImageList = null; - this.VirtualListSize = 0; - this.VirtualMode = false; + public bool GetCheckBoxes() + { return base.CheckBoxes; } - // Change the CheckBox setting while not in virtual mode - base.CheckBoxes = value; + public void SetCheckBoxes(bool value) + { + // Due to code in the base ListView class, turning off CheckBoxes on a virtual + // list always throws an InvalidOperationException. We have to do some major hacking + // to get around that + if (this.VirtualMode) + { + // Leave virtual mode + this.StateImageList = null; + this.VirtualListSize = 0; + this.VirtualMode = false; - // Reinstate virtual mode - this.VirtualMode = true; + // Change the CheckBox setting while not in virtual mode + base.CheckBoxes = value; - // Re-enact the bits that we lost by switching to virtual mode - this.ShowGroups = this.ShowGroups; - this.BuildList(true); - } else { - base.CheckBoxes = value; - // Initialize the state image list so we can display indetermined values. - this.InitializeStateImageList(); - } + // Reinstate virtual mode + this.VirtualMode = true; + + // Re-enact the bits that we lost by switching to virtual mode + this.ShowGroups = this.ShowGroups; + this.BuildList(true); + } + else + { + base.CheckBoxes = value; + // Initialize the state image list so we can display indetermined values. + this.InitializeStateImageList(); } } @@ -1212,12 +1312,15 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual Object CheckedObject { - get { + public virtual Object CheckedObject + { + get + { IList checkedObjects = this.CheckedObjects; return checkedObjects.Count == 1 ? checkedObjects[0] : null; } - set { + set + { this.CheckedObjects = new ArrayList(new Object[] { value }); } } @@ -1246,11 +1349,15 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual IList CheckedObjects { - get { + public virtual IList CheckedObjects + { + get + { ArrayList list = new ArrayList(); - if (this.CheckBoxes) { - for (int i = 0; i < this.GetItemCount(); i++) { + if (this.GetCheckBoxes()) + { + for (int i = 0; i < this.GetItemCount(); i++) + { OLVListItem olvi = this.GetItem(i); if (olvi.CheckState == CheckState.Checked) list.Add(olvi.RowObject); @@ -1258,21 +1365,24 @@ namespace BrightIdeasSoftware } return list; } - set { - if (!this.CheckBoxes) + set + { + if (!this.GetCheckBoxes()) return; Stopwatch sw = Stopwatch.StartNew(); // Set up an efficient way of testing for the presence of a particular model Hashtable table = new Hashtable(this.GetItemCount()); - if (value != null) { + if (value != null) + { foreach (object x in value) table[x] = true; } this.BeginUpdate(); - foreach (Object x in this.Objects) { + foreach (Object x in this.Objects) + { this.SetObjectCheckedness(x, table.ContainsKey(x) ? CheckState.Checked : CheckState.Unchecked); } this.EndUpdate(); @@ -1293,11 +1403,14 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual IEnumerable CheckedObjectsEnumerable { - get { + public virtual IEnumerable CheckedObjectsEnumerable + { + get + { return this.CheckedObjects; } - set { + set + { this.CheckedObjects = ObjectListView.EnumerableToArray(value, true); } } @@ -1307,8 +1420,10 @@ namespace BrightIdeasSoftware /// a specialised editor with it. /// [Editor("BrightIdeasSoftware.Design.OLVColumnCollectionEditor", "System.Drawing.Design.UITypeEditor")] - new public ListView.ColumnHeaderCollection Columns { - get { + new public ListView.ColumnHeaderCollection Columns + { + get + { return base.Columns; } } @@ -1319,7 +1434,8 @@ namespace BrightIdeasSoftware [Browsable(false), Obsolete("Use GetFilteredColumns() and OLVColumn.IsTileViewColumn instead"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public List ColumnsForTileView { + public List ColumnsForTileView + { get { return this.GetFilteredColumns(View.Tile); } } @@ -1327,10 +1443,13 @@ namespace BrightIdeasSoftware /// Return the visible columns in the order they are displayed to the user /// [Browsable(false)] - public virtual List ColumnsInDisplayOrder { - get { + public virtual List ColumnsInDisplayOrder + { + get + { OLVColumn[] columnsInDisplayOrder = new OLVColumn[this.Columns.Count]; - foreach (OLVColumn col in this.Columns) { + foreach (OLVColumn col in this.Columns) + { columnsInDisplayOrder[col.DisplayIndex] = col; } return new List(columnsInDisplayOrder); @@ -1342,12 +1461,15 @@ namespace BrightIdeasSoftware /// Get the area of the control that shows the list, minus any header control /// [Browsable(false)] - public Rectangle ContentRectangle { - get { + public Rectangle ContentRectangle + { + get + { Rectangle r = this.ClientRectangle; // If the listview has a header control, remove the header from the control area - if ((this.View == View.Details || this.ShowHeaderInAllViews) && this.HeaderControl != null) { + if ((this.View == View.Details || this.ShowHeaderInAllViews) && this.HeaderControl != null) + { Rectangle hdrBounds = new Rectangle(); NativeMethods.GetClientRect(this.HeaderControl.Handle, ref hdrBounds); r.Y = hdrBounds.Height; @@ -1364,7 +1486,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the control copy the selection to the clipboard when the user presses Ctrl-C?"), DefaultValue(true)] - public virtual bool CopySelectionOnControlC { + public virtual bool CopySelectionOnControlC + { get { return copySelectionOnControlC; } set { copySelectionOnControlC = value; } } @@ -1380,7 +1503,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the Ctrl-C copy process use the DragSource to create the Clipboard data object?"), DefaultValue(true)] - public bool CopySelectionOnControlCUsesDragSource { + public bool CopySelectionOnControlCUsesDragSource + { get { return this.copySelectionOnControlCUsesDragSource; } set { this.copySelectionOnControlCUsesDragSource = value; } } @@ -1398,7 +1522,8 @@ namespace BrightIdeasSoftware /// /// [Browsable(false)] - protected IList Decorations { + protected IList Decorations + { get { return this.decorations; } } private readonly List decorations = new List(); @@ -1410,7 +1535,8 @@ namespace BrightIdeasSoftware /// If you try to set this to null, it will revert to a HighlightTextRenderer [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public IRenderer DefaultRenderer { + public IRenderer DefaultRenderer + { get { return this.defaultRenderer; } set { this.defaultRenderer = value ?? new HighlightTextRenderer(); } } @@ -1422,7 +1548,8 @@ namespace BrightIdeasSoftware /// The row model for the row /// The column to be drawn /// The renderer used for drawing a cell. Must not return null. - public IRenderer GetCellRenderer(object model, OLVColumn column) { + public IRenderer GetCellRenderer(object model, OLVColumn column) + { IRenderer renderer = this.CellRendererGetter == null ? null : this.CellRendererGetter(model, column); return renderer ?? column.Renderer ?? this.DefaultRenderer; } @@ -1476,7 +1603,8 @@ namespace BrightIdeasSoftware /// Disabled objects cannot be selected or activated. /// /// Must not be null - public void DisableObject(object model) { + public void DisableObject(object model) + { ArrayList list = new ArrayList(); list.Add(model); this.DisableObjects(list); @@ -1493,7 +1621,7 @@ namespace BrightIdeasSoftware ArrayList list = ObjectListView.EnumerableToArray(models, false); foreach (object model in list) { - if (model == null) + if (model == null) continue; this.disabledObjects[model] = true; @@ -1536,7 +1664,7 @@ namespace BrightIdeasSoftware /// protected void ClearDisabledObjects() { - this.disabledObjects.Clear(); + this.disabledObjects.Clear(); } /// @@ -1544,7 +1672,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public IDragSource DragSource { + public IDragSource DragSource + { get { return this.dragSource; } set { this.dragSource = value; } } @@ -1564,15 +1693,18 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public IDropSink DropSink { + public IDropSink DropSink + { get { return this.dropSink; } - set { + set + { if (this.dropSink == value) return; // Stop listening for events on the old sink SimpleDropSink oldSink = this.dropSink as SimpleDropSink; - if (oldSink != null) { + if (oldSink != null) + { oldSink.CanDrop -= new EventHandler(this.DropSinkCanDrop); oldSink.Dropped -= new EventHandler(this.DropSinkDropped); oldSink.ModelCanDrop -= new EventHandler(this.DropSinkModelCanDrop); @@ -1586,7 +1718,8 @@ namespace BrightIdeasSoftware // Start listening for events on the new sink SimpleDropSink newSink = value as SimpleDropSink; - if (newSink != null) { + if (newSink != null) + { newSink.CanDrop += new EventHandler(this.DropSinkCanDrop); newSink.Dropped += new EventHandler(this.DropSinkDropped); newSink.ModelCanDrop += new EventHandler(this.DropSinkModelCanDrop); @@ -1610,7 +1743,7 @@ namespace BrightIdeasSoftware /// All instances of ObjectListView share the same editor registry. // ReSharper disable FieldCanBeMadeReadOnly.Global static public EditorRegistry EditorRegistry = new EditorRegistry(); -// ReSharper restore FieldCanBeMadeReadOnly.Global + // ReSharper restore FieldCanBeMadeReadOnly.Global /// /// Gets or sets the text that should be shown when there are no items in this list view. @@ -1621,14 +1754,18 @@ namespace BrightIdeasSoftware Description("When the list has no items, show this message in the control"), DefaultValue(null), Localizable(true)] - public virtual String EmptyListMsg { - get { + public virtual String EmptyListMsg + { + get + { TextOverlay overlay = this.EmptyListMsgOverlay as TextOverlay; return overlay == null ? null : overlay.Text; } - set { + set + { TextOverlay overlay = this.EmptyListMsgOverlay as TextOverlay; - if (overlay != null) { + if (overlay != null) + { overlay.Text = value; this.Invalidate(); } @@ -1643,12 +1780,15 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("What font should the 'list empty' message be drawn in?"), DefaultValue(null)] - public virtual Font EmptyListMsgFont { - get { + public virtual Font EmptyListMsgFont + { + get + { TextOverlay overlay = this.EmptyListMsgOverlay as TextOverlay; return overlay == null ? null : overlay.Font; } - set { + set + { TextOverlay overlay = this.EmptyListMsgOverlay as TextOverlay; if (overlay != null) overlay.Font = value; @@ -1659,9 +1799,11 @@ namespace BrightIdeasSoftware /// Return the font for the 'list empty' message or a reasonable default /// [Browsable(false)] - public virtual Font EmptyListMsgFontOrDefault { - get { - return this.EmptyListMsgFont ?? new Font("Tahoma", 14); + public virtual Font EmptyListMsgFontOrDefault + { + get + { + return this.EmptyListMsgFont ?? new Font("Tahoma", 14); } } @@ -1670,10 +1812,13 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual IOverlay EmptyListMsgOverlay { + public virtual IOverlay EmptyListMsgOverlay + { get { return this.emptyListMsgOverlay; } - set { - if (this.emptyListMsgOverlay != value) { + set + { + if (this.emptyListMsgOverlay != value) + { this.emptyListMsgOverlay = value; this.Invalidate(); } @@ -1696,11 +1841,13 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - virtual public IEnumerable FilteredObjects { - get { + virtual public IEnumerable FilteredObjects + { + get + { if (this.UseFiltering) return this.FilterObjects(this.Objects, this.ModelFilter, this.ListFilter); - + return this.Objects; } } @@ -1711,7 +1858,8 @@ namespace BrightIdeasSoftware /// If this is null, no filter menu will be built. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public FilterMenuBuilder FilterMenuBuildStrategy { + public FilterMenuBuilder FilterMenuBuildStrategy + { get { return filterMenuBuilder; } set { filterMenuBuilder = value; } } @@ -1731,9 +1879,11 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual Object FocusedObject { + public virtual Object FocusedObject + { get { return this.FocusedItem == null ? null : ((OLVListItem)this.FocusedItem).RowObject; } - set { + set + { OLVListItem item = this.ModelToItem(value); if (item != null) item.Focused = true; @@ -1745,7 +1895,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - new public ListViewGroupCollection Groups { + new public ListViewGroupCollection Groups + { get { return base.Groups; } } @@ -1756,11 +1907,14 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("The image list from which group header will take their images"), DefaultValue(null)] - public ImageList GroupImageList { + public ImageList GroupImageList + { get { return this.groupImageList; } - set { + set + { this.groupImageList = value; - if (this.Created) { + if (this.Created) + { NativeMethods.SetGroupImageList(this, value); } } @@ -1783,7 +1937,8 @@ namespace BrightIdeasSoftware Description("The format to use when suffixing item counts to group titles"), DefaultValue(null), Localizable(true)] - public virtual string GroupWithItemCountFormat { + public virtual string GroupWithItemCountFormat + { get { return groupWithItemCountFormat; } set { groupWithItemCountFormat = value; } } @@ -1793,8 +1948,10 @@ namespace BrightIdeasSoftware /// Return this.GroupWithItemCountFormat or a reasonable default /// [Browsable(false)] - public virtual string GroupWithItemCountFormatOrDefault { - get { + public virtual string GroupWithItemCountFormatOrDefault + { + get + { return String.IsNullOrEmpty(this.GroupWithItemCountFormat) ? "{0} [{1} items]" : this.GroupWithItemCountFormat; } } @@ -1814,7 +1971,8 @@ namespace BrightIdeasSoftware Description("The format to use when suffixing item counts to group titles"), DefaultValue(null), Localizable(true)] - public virtual string GroupWithItemCountSingularFormat { + public virtual string GroupWithItemCountSingularFormat + { get { return groupWithItemCountSingularFormat; } set { groupWithItemCountSingularFormat = value; } } @@ -1824,8 +1982,10 @@ namespace BrightIdeasSoftware /// Gets GroupWithItemCountSingularFormat or a reasonable default /// [Browsable(false)] - public virtual string GroupWithItemCountSingularFormatOrDefault { - get { + public virtual string GroupWithItemCountSingularFormatOrDefault + { + get + { return String.IsNullOrEmpty(this.GroupWithItemCountSingularFormat) ? "{0} [{1} item]" : this.GroupWithItemCountSingularFormat; } } @@ -1840,7 +2000,8 @@ namespace BrightIdeasSoftware Category("ObjectListView"), Description("Should the groups in this control be collapsible (Vista and later only)."), DefaultValue(true)] - public bool HasCollapsibleGroups { + public bool HasCollapsibleGroups + { get { return hasCollapsibleGroups; } set { hasCollapsibleGroups = value; } } @@ -1850,7 +2011,8 @@ namespace BrightIdeasSoftware /// Does this listview have a message that should be drawn when the list is empty? /// [Browsable(false)] - public virtual bool HasEmptyListMsg { + public virtual bool HasEmptyListMsg + { get { return !String.IsNullOrEmpty(this.EmptyListMsg); } } @@ -1858,8 +2020,10 @@ namespace BrightIdeasSoftware /// Get whether there are any overlays to be drawn /// [Browsable(false)] - public bool HasOverlays { - get { + public bool HasOverlays + { + get + { return (this.Overlays.Count > 2 || this.imageOverlay.Image != null || !String.IsNullOrEmpty(this.textOverlay.Text)); @@ -1870,7 +2034,8 @@ namespace BrightIdeasSoftware /// Gets the header control for the ListView /// [Browsable(false)] - public HeaderControl HeaderControl { + public HeaderControl HeaderControl + { get { return this.headerControl ?? (this.headerControl = new HeaderControl(this)); } } private HeaderControl headerControl; @@ -1882,9 +2047,11 @@ namespace BrightIdeasSoftware [DefaultValue(null)] [Browsable(false)] [Obsolete("Use a HeaderFormatStyle instead", false)] - public Font HeaderFont { + public Font HeaderFont + { get { return this.HeaderFormatStyle == null ? null : this.HeaderFormatStyle.Normal.Font; } - set { + set + { if (value == null && this.HeaderFormatStyle == null) return; @@ -1909,7 +2076,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("What style will be used to draw the control's header"), DefaultValue(null)] - public HeaderFormatStyle HeaderFormatStyle { + public HeaderFormatStyle HeaderFormatStyle + { get { return this.headerFormatStyle; } set { this.headerFormatStyle = value; } } @@ -1962,7 +2130,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Will the column headers be drawn strictly according to OS theme?"), DefaultValue(false)] - public bool HeaderUsesThemes { + public bool HeaderUsesThemes + { get { return this.headerUsesThemes; } set { this.headerUsesThemes = value; } } @@ -1982,9 +2151,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Will the text of the column headers be word wrapped?"), DefaultValue(false)] - public bool HeaderWordWrap { + public bool HeaderWordWrap + { get { return this.headerWordWrap; } - set { + set + { this.headerWordWrap = value; if (this.headerControl != null) this.headerControl.WordWrap = value; @@ -1996,8 +2167,10 @@ namespace BrightIdeasSoftware /// Gets the tool tip that shows tips for the column headers /// [Browsable(false)] - public ToolTipControl HeaderToolTip { - get { + public ToolTipControl HeaderToolTip + { + get + { return this.HeaderControl.ToolTip; } } @@ -2007,7 +2180,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual int HotRowIndex { + public virtual int HotRowIndex + { get { return this.hotRowIndex; } protected set { this.hotRowIndex = value; } } @@ -2018,7 +2192,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual int HotColumnIndex { + public virtual int HotColumnIndex + { get { return this.hotColumnIndex; } protected set { this.hotColumnIndex = value; } } @@ -2029,7 +2204,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual HitTestLocation HotCellHitLocation { + public virtual HitTestLocation HotCellHitLocation + { get { return this.hotCellHitLocation; } protected set { this.hotCellHitLocation = value; } } @@ -2064,7 +2240,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), Obsolete("Use HotRowIndex instead", false)] - public virtual int HotItemIndex { + public virtual int HotItemIndex + { get { return this.HotRowIndex; } } @@ -2081,9 +2258,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("How should the row under the cursor be highlighted"), DefaultValue(null)] - public virtual HotItemStyle HotItemStyle { + public virtual HotItemStyle HotItemStyle + { get { return this.hotItemStyle; } - set { + set + { if (this.HotItemStyle != null) this.RemoveOverlay(this.HotItemStyle.Overlay); this.hotItemStyle = value; @@ -2098,7 +2277,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual HotItemStyle HotItemStyleOrDefault { + public virtual HotItemStyle HotItemStyleOrDefault + { get { return this.HotItemStyle ?? ObjectListView.DefaultHotItemStyle; } } @@ -2108,7 +2288,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("How should hyperlinks be drawn"), DefaultValue(null)] - public virtual HyperlinkStyle HyperlinkStyle { + public virtual HyperlinkStyle HyperlinkStyle + { get { return this.hyperlinkStyle; } set { this.hyperlinkStyle = value; } } @@ -2120,7 +2301,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("The background of selected rows when the control is owner drawn"), DefaultValue(typeof(Color), "")] - public virtual Color SelectedBackColor { + public virtual Color SelectedBackColor + { get { return this.selectedBackColor; } set { this.selectedBackColor = value; } } @@ -2130,8 +2312,10 @@ namespace BrightIdeasSoftware /// Return the color should be used for the background of selected rows or a reasonable default /// [Browsable(false)] - public virtual Color SelectedBackColorOrDefault { - get { + public virtual Color SelectedBackColorOrDefault + { + get + { return this.SelectedBackColor.IsEmpty ? SystemColors.Highlight : this.SelectedBackColor; } } @@ -2142,7 +2326,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("The foreground color of selected rows (when the control is owner drawn)"), DefaultValue(typeof(Color), "")] - public virtual Color SelectedForeColor { + public virtual Color SelectedForeColor + { get { return this.selectedForeColor; } set { this.selectedForeColor = value; } } @@ -2152,8 +2337,10 @@ namespace BrightIdeasSoftware /// Return the color should be used for the foreground of selected rows or a reasonable default /// [Browsable(false)] - public virtual Color SelectedForeColorOrDefault { - get { + public virtual Color SelectedForeColorOrDefault + { + get + { return this.SelectedForeColor.IsEmpty ? SystemColors.HighlightText : this.SelectedForeColor; } } @@ -2194,7 +2381,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("When rows are copied or dragged, will data in hidden columns be included in the text? If this is false, only visible columns will be included."), DefaultValue(false)] - public virtual bool IncludeHiddenColumnsInDataTransfer { + public virtual bool IncludeHiddenColumnsInDataTransfer + { get { return includeHiddenColumnsInDataTransfer; } set { includeHiddenColumnsInDataTransfer = value; } } @@ -2219,7 +2407,8 @@ namespace BrightIdeasSoftware /// Return true if a cell edit operation is currently happening /// [Browsable(false)] - public virtual bool IsCellEditing { + public virtual bool IsCellEditing + { get { return this.cellEditor != null; } } @@ -2227,7 +2416,8 @@ namespace BrightIdeasSoftware /// Return true if the ObjectListView is being used within the development environment. /// [Browsable(false)] - public virtual bool IsDesignMode { + public virtual bool IsDesignMode + { get { return this.DesignMode; } } @@ -2236,7 +2426,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - virtual public bool IsFiltering { + virtual public bool IsFiltering + { get { return this.UseFiltering && (this.ModelFilter != null || this.ListFilter != null); } } @@ -2248,7 +2439,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("When the user types into a list, should the values in the current sort column be searched to find a match?"), DefaultValue(true)] - public virtual bool IsSearchOnSortColumn { + public virtual bool IsSearchOnSortColumn + { get { return isSearchOnSortColumn; } set { isSearchOnSortColumn = value; } } @@ -2270,9 +2462,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should this control will use a SimpleDropSink to receive drops."), DefaultValue(false)] - public virtual bool IsSimpleDropSink { + public virtual bool IsSimpleDropSink + { get { return this.DropSink != null; } - set { + set + { this.DropSink = value ? new SimpleDropSink() : null; } } @@ -2284,9 +2478,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should this control use a SimpleDragSource to initiate drags out from this control"), DefaultValue(false)] - public virtual bool IsSimpleDragSource { + public virtual bool IsSimpleDragSource + { get { return this.DragSource != null; } - set { + set + { this.DragSource = value ? new SimpleDragSource() : null; } } @@ -2296,7 +2492,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - new public ListViewItemCollection Items { + new public ListViewItemCollection Items + { get { return base.Items; } } @@ -2307,7 +2504,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("The owner drawn renderer that draws items when the list is in non-Details view."), DefaultValue(null)] - public IRenderer ItemRenderer { + public IRenderer ItemRenderer + { get { return itemRenderer; } set { itemRenderer = value; } } @@ -2319,7 +2517,8 @@ namespace BrightIdeasSoftware /// This is an alias for PrimarySortColumn [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual OLVColumn LastSortColumn { + public virtual OLVColumn LastSortColumn + { get { return this.PrimarySortColumn; } set { this.PrimarySortColumn = value; } } @@ -2330,7 +2529,8 @@ namespace BrightIdeasSoftware /// This is an alias for PrimarySortOrder [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual SortOrder LastSortOrder { + public virtual SortOrder LastSortOrder + { get { return this.PrimarySortOrder; } set { this.PrimarySortOrder = value; } } @@ -2343,9 +2543,11 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual IListFilter ListFilter { + public virtual IListFilter ListFilter + { get { return listFilter; } - set { + set + { listFilter = value; if (this.UseFiltering) this.UpdateFiltering(); @@ -2366,12 +2568,15 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual IModelFilter ModelFilter { + public virtual IModelFilter ModelFilter + { get { return modelFilter; } - set { + set + { modelFilter = value; this.NotifyNewModelFilter(); - if (this.UseFiltering) { + if (this.UseFiltering) + { this.UpdateFiltering(); // When the filter changes, it's likely/possible that the selection has also changed. @@ -2389,12 +2594,13 @@ namespace BrightIdeasSoftware /// Useful for hot item processing. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual OlvListViewHitTestInfo MouseMoveHitTest { + public virtual OlvListViewHitTestInfo MouseMoveHitTest + { get { return mouseMoveHitTest; } private set { mouseMoveHitTest = value; } } private OlvListViewHitTestInfo mouseMoveHitTest; - + /// /// Gets or sets the list of groups shown by the listview. /// @@ -2409,7 +2615,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public IList OLVGroups { + public IList OLVGroups + { get { return this.olvGroups; } set { this.olvGroups = value; } } @@ -2420,7 +2627,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public IEnumerable CollapsedGroups { + public IEnumerable CollapsedGroups + { get { if (this.OLVGroups != null) @@ -2463,7 +2671,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the DrawColumnHeader event be triggered"), DefaultValue(false)] - public bool OwnerDrawnHeader { + public bool OwnerDrawnHeader + { get { return ownerDrawnHeader; } set { ownerDrawnHeader = value; } } @@ -2487,7 +2696,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual IEnumerable Objects { + public virtual IEnumerable Objects + { get { return this.objects; } set { this.SetObjects(value, true); } } @@ -2499,7 +2709,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual IEnumerable ObjectsForClustering { + public virtual IEnumerable ObjectsForClustering + { get { return this.Objects; } } @@ -2509,9 +2720,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("The image that will be drawn over the top of the ListView"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] - public ImageOverlay OverlayImage { + public ImageOverlay OverlayImage + { get { return this.imageOverlay; } - set { + set + { if (this.imageOverlay == value) return; @@ -2528,9 +2741,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("The text that will be drawn over the top of the ListView"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] - public TextOverlay OverlayText { + public TextOverlay OverlayText + { get { return this.textOverlay; } - set { + set + { if (this.textOverlay == value) return; @@ -2550,7 +2765,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public int OverlayTransparency { + public int OverlayTransparency + { get { return this.overlayTransparency; } set { this.overlayTransparency = Math.Min(255, Math.Max(0, value)); } } @@ -2564,7 +2780,8 @@ namespace BrightIdeasSoftware /// don't mess with the overlays that you didn't create. /// [Browsable(false)] - protected IList Overlays { + protected IList Overlays + { get { return this.overlays; } } private readonly List overlays = new List(); @@ -2583,7 +2800,8 @@ namespace BrightIdeasSoftware [Category("Appearance"), Description("Should the ListView do its own rendering"), DefaultValue(true)] - public new bool OwnerDraw { + public new bool OwnerDraw + { get { return base.OwnerDraw; } set { base.OwnerDraw = value; } } @@ -2606,9 +2824,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Will primary checkboxes persistent their values across list rebuilds"), DefaultValue(true)] - public virtual bool PersistentCheckBoxes { + public virtual bool PersistentCheckBoxes + { get { return persistentCheckBoxes; } - set { + set + { if (persistentCheckBoxes == value) return; persistentCheckBoxes = value; @@ -2621,7 +2841,8 @@ namespace BrightIdeasSoftware /// Gets or sets a dictionary that remembers the check state of model objects /// /// This is used when PersistentCheckBoxes is true and for virtual lists. - protected Dictionary CheckStateMap { + protected Dictionary CheckStateMap + { get { return checkStateMap ?? (checkStateMap = new Dictionary()); } set { checkStateMap = value; } } @@ -2632,11 +2853,13 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual OLVColumn PrimarySortColumn { + public virtual OLVColumn PrimarySortColumn + { get { return this.primarySortColumn; } - set { + set + { this.primarySortColumn = value; - if (this.TintSortColumn) + if (this.TintSortColumn) this.SelectedColumn = value; } } @@ -2647,7 +2870,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual SortOrder PrimarySortOrder { + public virtual SortOrder PrimarySortOrder + { get { return primarySortOrder; } set { primarySortOrder = value; } } @@ -2662,7 +2886,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should non-editable checkboxes be drawn as disabled?"), DefaultValue(false)] - public virtual bool RenderNonEditableCheckboxesAsDisabled { + public virtual bool RenderNonEditableCheckboxesAsDisabled + { get { return renderNonEditableCheckboxesAsDisabled; } set { renderNonEditableCheckboxesAsDisabled = value; } } @@ -2681,9 +2906,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Specify the height of each row in pixels. -1 indicates default height"), DefaultValue(-1)] - public virtual int RowHeight { + public virtual int RowHeight + { get { return rowHeight; } - set { + set + { if (value < 1) rowHeight = -1; else @@ -2691,7 +2918,7 @@ namespace BrightIdeasSoftware if (this.DesignMode) return; this.SetupBaseImageList(); - if (this.CheckBoxes) + if (this.GetCheckBoxes()) this.InitializeStateImageList(); } } @@ -2701,9 +2928,12 @@ namespace BrightIdeasSoftware /// How many pixels high is each row? /// [Browsable(false)] - public virtual int RowHeightEffective { - get { - switch (this.View) { + public virtual int RowHeightEffective + { + get + { + switch (this.View) + { case View.List: case View.SmallIcon: case View.Details: @@ -2715,7 +2945,7 @@ namespace BrightIdeasSoftware case View.LargeIcon: if (this.LargeImageList == null) return this.Font.Height; - + return Math.Max(this.LargeImageList.ImageSize.Height, this.Font.Height); default: @@ -2729,8 +2959,10 @@ namespace BrightIdeasSoftware /// How many rows appear on each page of this control /// [Browsable(false)] - public virtual int RowsPerPage { - get { + public virtual int RowsPerPage + { + get + { return NativeMethods.GetCountPerPage(this); } } @@ -2741,7 +2973,8 @@ namespace BrightIdeasSoftware /// There is no user interface for this setting. It must be set programmatically. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual OLVColumn SecondarySortColumn { + public virtual OLVColumn SecondarySortColumn + { get { return this.secondarySortColumn; } set { this.secondarySortColumn = value; } } @@ -2752,7 +2985,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual SortOrder SecondarySortOrder { + public virtual SortOrder SecondarySortOrder + { get { return this.secondarySortOrder; } set { this.secondarySortOrder = value; } } @@ -2764,7 +2998,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the control select all rows when the user presses Ctrl-A?"), DefaultValue(true)] - public virtual bool SelectAllOnControlA { + public virtual bool SelectAllOnControlA + { get { return selectAllOnControlA; } set { selectAllOnControlA = value; } } @@ -2779,13 +3014,18 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("When the user right clicks on the column headers, should a menu be presented which will allow them to choose which columns will be shown in the view?"), DefaultValue(true)] - public virtual bool SelectColumnsOnRightClick { + public virtual bool SelectColumnsOnRightClick + { get { return this.SelectColumnsOnRightClickBehaviour != ColumnSelectBehaviour.None; } - set { - if (value) { + set + { + if (value) + { if (this.SelectColumnsOnRightClickBehaviour == ColumnSelectBehaviour.None) this.SelectColumnsOnRightClickBehaviour = ColumnSelectBehaviour.InlineMenu; - } else { + } + else + { this.SelectColumnsOnRightClickBehaviour = ColumnSelectBehaviour.None; } } @@ -2797,7 +3037,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("When the user right clicks on the column headers, how will the user be able to select columns?"), DefaultValue(ColumnSelectBehaviour.InlineMenu)] - public virtual ColumnSelectBehaviour SelectColumnsOnRightClickBehaviour { + public virtual ColumnSelectBehaviour SelectColumnsOnRightClickBehaviour + { get { return selectColumnsOnRightClickBehaviour; } set { selectColumnsOnRightClickBehaviour = value; } } @@ -2812,7 +3053,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("When the column select inline menu is open, should it stay open after an item is selected?"), DefaultValue(true)] - public virtual bool SelectColumnsMenuStaysOpen { + public virtual bool SelectColumnsMenuStaysOpen + { get { return selectColumnsMenuStaysOpen; } set { selectColumnsMenuStaysOpen = value; } } @@ -2832,13 +3074,18 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public OLVColumn SelectedColumn { + public OLVColumn SelectedColumn + { get { return this.selectedColumn; } - set { + set + { this.selectedColumn = value; - if (value == null) { + if (value == null) + { this.RemoveDecoration(this.selectedColumnDecoration); - } else { + } + else + { if (!this.HasDecoration(this.selectedColumnDecoration)) this.AddDecoration(this.selectedColumnDecoration); } @@ -2852,7 +3099,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual IDecoration SelectedRowDecoration { + public virtual IDecoration SelectedRowDecoration + { get { return this.selectedRowDecoration; } set { this.selectedRowDecoration = value; } } @@ -2868,9 +3116,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("The color that will be used to tint the selected column"), DefaultValue(typeof(Color), "")] - public virtual Color SelectedColumnTint { + public virtual Color SelectedColumnTint + { get { return selectedColumnTint; } - set { + set + { this.selectedColumnTint = value.A == 255 ? Color.FromArgb(15, value) : value; this.selectedColumnDecoration.Tint = this.selectedColumnTint; } @@ -2883,9 +3133,11 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual int SelectedIndex { + public virtual int SelectedIndex + { get { return this.SelectedIndices.Count == 1 ? this.SelectedIndices[0] : -1; } - set { + set + { this.SelectedIndices.Clear(); if (value >= 0 && value < this.Items.Count) this.SelectedIndices.Add(value); @@ -2897,11 +3149,14 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual OLVListItem SelectedItem { - get { + public virtual OLVListItem SelectedItem + { + get + { return this.SelectedIndices.Count == 1 ? this.GetItem(this.SelectedIndices[0]) : null; } - set { + set + { this.SelectedIndices.Clear(); if (value != null) this.SelectedIndices.Add(value.Index); @@ -2916,18 +3171,21 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual Object SelectedObject { - get { + public virtual Object SelectedObject + { + get + { return this.SelectedIndices.Count == 1 ? this.GetModelObject(this.SelectedIndices[0]) : null; } - set { + set + { // If the given model is already selected, don't do anything else (prevents an flicker) object selectedObject = this.SelectedObject; if (selectedObject != null && selectedObject.Equals(value)) return; this.SelectedIndices.Clear(); - this.SelectObject(value, true); + this.SelectObject(value, true); } } @@ -2937,16 +3195,19 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual IList SelectedObjects { - get { + public virtual IList SelectedObjects + { + get + { ArrayList list = new ArrayList(); foreach (int index in this.SelectedIndices) - list.Add(this.GetModelObject(index)); + list.Add(this.GetModelObject(index)); return list; } - set { + set + { this.SelectedIndices.Clear(); - this.SelectObjects(value); + this.SelectObjects(value); } } @@ -2957,7 +3218,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("When the user right clicks on the column headers, should a menu be presented which will allow them to perform common tasks on the listview?"), DefaultValue(false)] - public virtual bool ShowCommandMenuOnRightClick { + public virtual bool ShowCommandMenuOnRightClick + { get { return showCommandMenuOnRightClick; } set { showCommandMenuOnRightClick = value; } } @@ -2970,7 +3232,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("If this is true, right clicking on a column header will show a Filter menu option"), DefaultValue(true)] - public bool ShowFilterMenuOnRightClick { + public bool ShowFilterMenuOnRightClick + { get { return showFilterMenuOnRightClick; } set { showFilterMenuOnRightClick = value; } } @@ -2982,11 +3245,13 @@ namespace BrightIdeasSoftware [Category("Appearance"), Description("Should the list view show items in groups?"), DefaultValue(true)] - new public virtual bool ShowGroups { + new public virtual bool ShowGroups + { get { return base.ShowGroups; } - set { + set + { this.GroupImageList = this.GroupImageList; - base.ShowGroups = value; + base.ShowGroups = value; } } @@ -3002,7 +3267,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the list view show sort indicators in the column headers?"), DefaultValue(true)] - public virtual bool ShowSortIndicators { + public virtual bool ShowSortIndicators + { get { return showSortIndicators; } set { showSortIndicators = value; } } @@ -3017,9 +3283,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the list view show images on subitems?"), DefaultValue(false)] - public virtual bool ShowImagesOnSubItems { + public virtual bool ShowImagesOnSubItems + { get { return showImagesOnSubItems; } - set { + set + { showImagesOnSubItems = value; if (this.Created) this.ApplyExtendedStyles(); @@ -3038,7 +3306,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Will group titles be suffixed with a count of the items in the group?"), DefaultValue(false)] - public virtual bool ShowItemCountOnGroups { + public virtual bool ShowItemCountOnGroups + { get { return showItemCountOnGroups; } set { showItemCountOnGroups = value; } } @@ -3069,9 +3338,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Will the control will show column headers in all views?"), DefaultValue(true)] - public bool ShowHeaderInAllViews { + public bool ShowHeaderInAllViews + { get { return ObjectListView.IsVistaOrLater && showHeaderInAllViews; } - set { + set + { if (showHeaderInAllViews == value) return; @@ -3083,13 +3354,14 @@ namespace BrightIdeasSoftware // If the header is being hidden, we have to recreate the control // to remove the style (not sure why this is) - if (showHeaderInAllViews) + if (showHeaderInAllViews) this.ApplyExtendedStyles(); - else + else this.RecreateHandle(); // Still more complications. The change doesn't become visible until the View is changed - if (this.View != View.Details) { + if (this.View != View.Details) + { View temp = this.View; this.View = View.Details; this.View = temp; @@ -3107,14 +3379,15 @@ namespace BrightIdeasSoftware /// as this will work: /// listView1.SmallImageList = listView1.SmallImageList; /// - new public ImageList SmallImageList { - get { return this.shadowedImageList; } - set { - this.shadowedImageList = value; - if (this.UseSubItemCheckBoxes) - this.SetupSubItemCheckBoxes(); - this.SetupBaseImageList(); - } + public ImageList GetSmallImageList() + { return this.shadowedImageList; } + + public void SetSmallImageList(ImageList value) + { + this.shadowedImageList = value; + if (this.UseSubItemCheckBoxes) + this.SetupSubItemCheckBoxes(); + this.SetupBaseImageList(); } private ImageList shadowedImageList; @@ -3122,8 +3395,10 @@ namespace BrightIdeasSoftware /// Return the size of the images in the small image list or a reasonable default /// [Browsable(false)] - public virtual Size SmallImageSize { - get { + public virtual Size SmallImageSize + { + get + { return this.BaseSmallImageList == null ? new Size(16, 16) : this.BaseSmallImageList.ImageSize; } } @@ -3135,7 +3410,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("When the listview is grouped, should the items be sorted by the primary column? If this is false, the items will be sorted by the same column as they are grouped."), DefaultValue(true)] - public virtual bool SortGroupItemsByPrimaryColumn { + public virtual bool SortGroupItemsByPrimaryColumn + { get { return this.sortGroupItemsByPrimaryColumn; } set { this.sortGroupItemsByPrimaryColumn = value; } } @@ -3148,9 +3424,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("How many pixels of space will be between groups"), DefaultValue(0)] - public virtual int SpaceBetweenGroups { + public virtual int SpaceBetweenGroups + { get { return this.spaceBetweenGroups; } - set { + set + { if (this.spaceBetweenGroups == value) return; @@ -3160,7 +3438,8 @@ namespace BrightIdeasSoftware } private int spaceBetweenGroups; - private void SetGroupSpacing() { + private void SetGroupSpacing() + { if (!this.IsHandleCreated) return; @@ -3177,9 +3456,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the sort column show a slight tinting?"), DefaultValue(false)] - public virtual bool TintSortColumn { + public virtual bool TintSortColumn + { get { return this.tintSortColumn; } - set { + set + { this.tintSortColumn = value; if (value && this.PrimarySortColumn != null) this.SelectedColumn = this.PrimarySortColumn; @@ -3200,12 +3481,14 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the primary column have a checkbox that behaves as a tri-state checkbox?"), DefaultValue(false)] - public virtual bool TriStateCheckBoxes { + public virtual bool TriStateCheckBoxes + { get { return triStateCheckBoxes; } - set { + set + { triStateCheckBoxes = value; - if (value && !this.CheckBoxes) - this.CheckBoxes = true; + if (value && !this.GetCheckBoxes()) + this.SetCheckBoxes(true); this.InitializeStateImageList(); } } @@ -3226,19 +3509,23 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual int TopItemIndex { - get { + public virtual int TopItemIndex + { + get + { if (this.View == View.Details && this.IsHandleCreated) return NativeMethods.GetTopIndex(this); - + return -1; } - set { + set + { int newTopIndex = Math.Min(value, this.GetItemCount() - 1); - if (this.View != View.Details || newTopIndex < 0) + if (this.View != View.Details || newTopIndex < 0) return; - try { + try + { this.TopItem = this.Items[newTopIndex]; // Setting the TopItem sometimes gives off by one errors, @@ -3246,7 +3533,8 @@ namespace BrightIdeasSoftware if (this.TopItem != null && this.TopItem.Index != newTopIndex) this.TopItem = this.GetItem(newTopIndex); } - catch (NullReferenceException) { + catch (NullReferenceException) + { // There is a bug in the .NET code where setting the TopItem // will sometimes throw null reference exceptions // There is nothing we can do to get around it. @@ -3295,7 +3583,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("When resizing a column by dragging its divider, should any space filling columns be resized at each mouse move?"), DefaultValue(true)] - public virtual bool UpdateSpaceFillingColumnsWhenDraggingColumnDivider { + public virtual bool UpdateSpaceFillingColumnsWhenDraggingColumnDivider + { get { return updateSpaceFillingColumnsWhenDraggingColumnDivider; } set { updateSpaceFillingColumnsWhenDraggingColumnDivider = value; } } @@ -3307,7 +3596,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("The background color of selected rows when the control doesn't have the focus"), DefaultValue(typeof(Color), "")] - public virtual Color UnfocusedSelectedBackColor { + public virtual Color UnfocusedSelectedBackColor + { get { return this.unfocusedSelectedBackColor; } set { this.unfocusedSelectedBackColor = value; } } @@ -3317,8 +3607,10 @@ namespace BrightIdeasSoftware /// Return the color should be used for the background of selected rows when the control doesn't have the focus or a reasonable default /// [Browsable(false)] - public virtual Color UnfocusedSelectedBackColorOrDefault { - get { + public virtual Color UnfocusedSelectedBackColorOrDefault + { + get + { return this.UnfocusedSelectedBackColor.IsEmpty ? SystemColors.Control : this.UnfocusedSelectedBackColor; } } @@ -3329,7 +3621,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("The foreground color of selected rows when the control is owner drawn and doesn't have the focus"), DefaultValue(typeof(Color), "")] - public virtual Color UnfocusedSelectedForeColor { + public virtual Color UnfocusedSelectedForeColor + { get { return this.unfocusedSelectedForeColor; } set { this.unfocusedSelectedForeColor = value; } } @@ -3339,8 +3632,10 @@ namespace BrightIdeasSoftware /// Return the color should be used for the foreground of selected rows when the control doesn't have the focus or a reasonable default /// [Browsable(false)] - public virtual Color UnfocusedSelectedForeColorOrDefault { - get { + public virtual Color UnfocusedSelectedForeColorOrDefault + { + get + { return this.UnfocusedSelectedForeColor.IsEmpty ? SystemColors.ControlText : this.UnfocusedSelectedForeColor; } } @@ -3354,7 +3649,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the list view use a different backcolor to alternate rows?"), DefaultValue(false)] - public virtual bool UseAlternatingBackColors { + public virtual bool UseAlternatingBackColors + { get { return useAlternatingBackColors; } set { useAlternatingBackColors = value; } } @@ -3379,7 +3675,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should FormatCell events be triggered to every cell that is built?"), DefaultValue(false)] - public bool UseCellFormatEvents { + public bool UseCellFormatEvents + { get { return useCellFormatEvents; } set { useCellFormatEvents = value; } } @@ -3392,7 +3689,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the selected row be drawn with non-standard foreground and background colors?"), DefaultValue(false)] - public bool UseCustomSelectionColors { + public bool UseCustomSelectionColors + { get { return false; } // ReSharper disable once ValueParameterNotUsed set { } @@ -3425,13 +3723,15 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the list use the same hot item and selection mechanism as Vista?"), DefaultValue(false)] - public bool UseExplorerTheme { + public bool UseExplorerTheme + { get { return useExplorerTheme; } - set { + set + { useExplorerTheme = value; if (this.Created) NativeMethods.SetWindowTheme(this.Handle, value ? "explorer" : "", null); - + this.OwnerDraw = !value; } } @@ -3443,9 +3743,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the list enable filtering?"), DefaultValue(false)] - virtual public bool UseFiltering { + virtual public bool UseFiltering + { get { return useFiltering; } - set { + set + { if (useFiltering == value) return; useFiltering = value; @@ -3463,9 +3765,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should an image be drawn in a column's header when that column is being used for filtering?"), DefaultValue(false)] - virtual public bool UseFilterIndicator { + virtual public bool UseFilterIndicator + { get { return useFilterIndicator; } - set { + set + { if (this.useFilterIndicator == value) return; useFilterIndicator = value; @@ -3489,7 +3793,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should controls (checkboxes or buttons) that are under the mouse be drawn hot?"), DefaultValue(true)] - public bool UseHotControls { + public bool UseHotControls + { get { return this.useHotControls; } set { this.useHotControls = value; } } @@ -3501,9 +3806,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should HotTracking be used? Hot tracking applies special formatting to the row under the cursor"), DefaultValue(false)] - public bool UseHotItem { + public bool UseHotItem + { get { return this.useHotItem; } - set { + set + { this.useHotItem = value; if (value) this.AddOverlay(this.HotItemStyleOrDefault.Overlay); @@ -3519,9 +3826,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should hyperlinks be shown on this control?"), DefaultValue(false)] - public bool UseHyperlinks { + public bool UseHyperlinks + { get { return this.useHyperlinks; } - set { + set + { this.useHyperlinks = value; if (value && this.HyperlinkStyle == null) this.HyperlinkStyle = new HyperlinkStyle(); @@ -3537,7 +3846,8 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should this control show overlays"), DefaultValue(true)] - public bool UseOverlays { + public bool UseOverlays + { get { return this.useOverlays; } set { this.useOverlays = value; } } @@ -3552,9 +3862,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should this control be configured to show check boxes on subitems."), DefaultValue(false)] - public bool UseSubItemCheckBoxes { + public bool UseSubItemCheckBoxes + { get { return this.useSubItemCheckBoxes; } - set { + set + { this.useSubItemCheckBoxes = value; if (value) this.SetupSubItemCheckBoxes(); @@ -3582,23 +3894,27 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the list use a translucent selection mechanism (like Vista)"), DefaultValue(false)] - public bool UseTranslucentSelection { + public bool UseTranslucentSelection + { get { return useTranslucentSelection; } - set { + set + { useTranslucentSelection = value; - if (value) { + if (value) + { RowBorderDecoration rbd = new RowBorderDecoration(); rbd.BorderPen = new Pen(Color.FromArgb(154, 223, 251)); rbd.FillBrush = new SolidBrush(Color.FromArgb(48, 163, 217, 225)); rbd.BoundsPadding = new Size(0, 0); rbd.CornerRounding = 6.0f; this.SelectedRowDecoration = rbd; - } else + } + else this.SelectedRowDecoration = null; } } private bool useTranslucentSelection; - + /// /// Gets or sets if the ObjectListView will use a translucent hot row highlighting mechanism like Vista. /// @@ -3615,11 +3931,14 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should the list use a translucent hot row highlighting mechanism (like Vista)"), DefaultValue(false)] - public bool UseTranslucentHotItem { + public bool UseTranslucentHotItem + { get { return useTranslucentHotItem; } - set { + set + { useTranslucentHotItem = value; - if (value) { + if (value) + { RowBorderDecoration rbd = new RowBorderDecoration(); rbd.BorderPen = new Pen(Color.FromArgb(154, 223, 251)); rbd.BoundsPadding = new Size(0, 0); @@ -3629,7 +3948,8 @@ namespace BrightIdeasSoftware HotItemStyle his = new HotItemStyle(); his.Decoration = rbd; this.HotItemStyle = his; - } else + } + else this.HotItemStyle = null; this.UseHotItem = value; } @@ -3647,14 +3967,18 @@ namespace BrightIdeasSoftware new public View View { get { return base.View; } - set { + set + { if (base.View == value) return; - if (this.Frozen) { + if (this.Frozen) + { base.View = value; this.SetupBaseImageList(); - } else { + } + else + { this.Freeze(); if (value == View.Tile) @@ -3682,12 +4006,15 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual BooleanCheckStateGetterDelegate BooleanCheckStateGetter { - set { + public virtual BooleanCheckStateGetterDelegate BooleanCheckStateGetter + { + set + { if (value == null) this.CheckStateGetter = null; else - this.CheckStateGetter = delegate(Object x) { + this.CheckStateGetter = delegate (Object x) + { return value(x) ? CheckState.Checked : CheckState.Unchecked; }; } @@ -3705,12 +4032,15 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual BooleanCheckStatePutterDelegate BooleanCheckStatePutter { - set { + public virtual BooleanCheckStatePutterDelegate BooleanCheckStatePutter + { + set + { if (value == null) this.CheckStatePutter = null; else - this.CheckStatePutter = delegate(Object x, CheckState state) { + this.CheckStatePutter = delegate (Object x, CheckState state) + { bool isChecked = (state == CheckState.Checked); return value(x, isChecked) ? CheckState.Checked : CheckState.Unchecked; }; @@ -3721,8 +4051,10 @@ namespace BrightIdeasSoftware /// Gets whether or not this listview is capabale of showing groups /// [Browsable(false)] - public virtual bool CanShowGroups { - get { + public virtual bool CanShowGroups + { + get + { return true; } } @@ -3738,7 +4070,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual bool CanUseApplicationIdle { + public virtual bool CanUseApplicationIdle + { get { return this.canUseApplicationIdle; } set { this.canUseApplicationIdle = value; } } @@ -3776,7 +4109,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual CellToolTipGetterDelegate CellToolTipGetter { + public virtual CellToolTipGetterDelegate CellToolTipGetter + { get { return cellToolTipGetter; } set { cellToolTipGetter = value; } } @@ -3795,23 +4129,30 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("The name of the property or field that holds the 'checkedness' of the model"), DefaultValue(null)] - public virtual string CheckedAspectName { + public virtual string CheckedAspectName + { get { return checkedAspectName; } - set { + set + { checkedAspectName = value; - if (String.IsNullOrEmpty(checkedAspectName)) { + if (String.IsNullOrEmpty(checkedAspectName)) + { this.checkedAspectMunger = null; this.CheckStateGetter = null; this.CheckStatePutter = null; - } else { + } + else + { this.checkedAspectMunger = new Munger(checkedAspectName); - this.CheckStateGetter = delegate(Object modelObject) { + this.CheckStateGetter = delegate (Object modelObject) + { bool? result = this.checkedAspectMunger.GetValue(modelObject) as bool?; if (result.HasValue) return result.Value ? CheckState.Checked : CheckState.Unchecked; return this.TriStateCheckBoxes ? CheckState.Indeterminate : CheckState.Unchecked; }; - this.CheckStatePutter = delegate(Object modelObject, CheckState newValue) { + this.CheckStatePutter = delegate (Object modelObject, CheckState newValue) + { if (this.TriStateCheckBoxes && newValue == CheckState.Indeterminate) this.checkedAspectMunger.PutValue(modelObject, null); else @@ -3834,7 +4175,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual CheckStateGetterDelegate CheckStateGetter { + public virtual CheckStateGetterDelegate CheckStateGetter + { get { return checkStateGetter; } set { checkStateGetter = value; } } @@ -3847,7 +4189,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual CheckStatePutterDelegate CheckStatePutter { + public virtual CheckStatePutterDelegate CheckStatePutter + { get { return checkStatePutter; } set { checkStatePutter = value; } } @@ -3869,7 +4212,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual SortDelegate CustomSorter { + public virtual SortDelegate CustomSorter + { get { return customSorter; } set { customSorter = value; } } @@ -3885,7 +4229,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual HeaderToolTipGetterDelegate HeaderToolTipGetter { + public virtual HeaderToolTipGetterDelegate HeaderToolTipGetter + { get { return headerToolTipGetter; } set { headerToolTipGetter = value; } } @@ -3911,7 +4256,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual RowFormatterDelegate RowFormatter { + public virtual RowFormatterDelegate RowFormatter + { get { return rowFormatter; } set { rowFormatter = value; } } @@ -3926,9 +4272,10 @@ namespace BrightIdeasSoftware /// /// The model object to be displayed /// See AddObjects() for more details - public virtual void AddObject(object modelObject) { + public virtual void AddObject(object modelObject) + { if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate() { this.AddObject(modelObject); }); + this.Invoke((MethodInvoker)delegate () { this.AddObject(modelObject); }); else this.AddObjects(new object[] { modelObject }); } @@ -3943,9 +4290,11 @@ namespace BrightIdeasSoftware /// No check is performed to see if any of the objects are already in the ListView. /// Null objects are silently ignored. /// - public virtual void AddObjects(ICollection modelObjects) { - if (this.InvokeRequired) { - this.Invoke((MethodInvoker)delegate() { this.AddObjects(modelObjects); }); + public virtual void AddObjects(ICollection modelObjects) + { + if (this.InvokeRequired) + { + this.Invoke((MethodInvoker)delegate () { this.AddObjects(modelObjects); }); return; } this.InsertObjects(ObjectListView.EnumerableCount(this.Objects), modelObjects); @@ -3955,8 +4304,10 @@ namespace BrightIdeasSoftware /// /// Resize the columns to the maximum of the header width and the data. /// - public virtual void AutoResizeColumns() { - foreach (OLVColumn c in this.Columns) { + public virtual void AutoResizeColumns() + { + foreach (OLVColumn c in this.Columns) + { this.AutoResizeColumn(c.Index, ColumnHeaderAutoResizeStyle.HeaderSize); } } @@ -3972,14 +4323,17 @@ namespace BrightIdeasSoftware /// second time through. Use to force all columns /// to change their size. /// - public virtual void AutoSizeColumns() { + public virtual void AutoSizeColumns() + { // If we are supposed to resize to content, but if there is no content, // resize to the header size instead. ColumnHeaderAutoResizeStyle resizeToContentStyle = this.GetItemCount() == 0 ? ColumnHeaderAutoResizeStyle.HeaderSize : ColumnHeaderAutoResizeStyle.ColumnContent; - foreach (ColumnHeader column in this.Columns) { - switch (column.Width) { + foreach (ColumnHeader column in this.Columns) + { + switch (column.Width) + { case 0: this.AutoResizeColumn(column.Index, resizeToContentStyle); break; @@ -3994,7 +4348,8 @@ namespace BrightIdeasSoftware /// Organise the view items into groups, based on the last sort column or the first column /// if there is no last sort column /// - public virtual void BuildGroups() { + public virtual void BuildGroups() + { this.BuildGroups(this.PrimarySortColumn, this.PrimarySortOrder == SortOrder.None ? SortOrder.Ascending : this.PrimarySortOrder); } @@ -4011,7 +4366,8 @@ namespace BrightIdeasSoftware /// /// The column whose values should be used for sorting. /// - public virtual void BuildGroups(OLVColumn column, SortOrder order) { + public virtual void BuildGroups(OLVColumn column, SortOrder order) + { // Sanity if (this.GetItemCount() == 0 || this.Columns.Count == 0) return; @@ -4027,10 +4383,12 @@ namespace BrightIdeasSoftware this.OnAfterSorting(new AfterSortingEventArgs(args)); } - private BeforeSortingEventArgs BuildBeforeSortingEventArgs(OLVColumn column, SortOrder order) { + private BeforeSortingEventArgs BuildBeforeSortingEventArgs(OLVColumn column, SortOrder order) + { OLVColumn groupBy = this.AlwaysGroupByColumn ?? column ?? this.GetColumn(0); SortOrder groupByOrder = this.AlwaysGroupBySortOrder; - if (order == SortOrder.None) { + if (order == SortOrder.None) + { order = this.Sorting; if (order == SortOrder.None) order = SortOrder.Ascending; @@ -4059,7 +4417,8 @@ namespace BrightIdeasSoftware /// How will the secondary values be sorted /// This method does not trigger sorting events. Use BuildGroups() to do that public virtual void BuildGroups(OLVColumn groupByColumn, SortOrder groupByOrder, - OLVColumn column, SortOrder order, OLVColumn secondaryColumn, SortOrder secondaryOrder) { + OLVColumn column, SortOrder order, OLVColumn secondaryColumn, SortOrder secondaryOrder) + { // Sanity checks if (groupByColumn == null) return; @@ -4068,7 +4427,7 @@ namespace BrightIdeasSoftware // this, iterating over the Items will not work correctly if the ListView handle // has not yet been created. #pragma warning disable 168 -// ReSharper disable once UnusedVariable + // ReSharper disable once UnusedVariable int dummy = this.Items.Count; #pragma warning restore 168 @@ -4085,7 +4444,7 @@ namespace BrightIdeasSoftware return; // If the event didn't create them for us, use our default strategy - if (args.Groups == null) + if (args.Groups == null) args.Groups = this.MakeGroups(parms); // Give the world a chance to munge the groups before they are created @@ -4108,11 +4467,13 @@ namespace BrightIdeasSoftware /// /// protected virtual GroupingParameters CollectGroupingParameters(OLVColumn groupByColumn, SortOrder groupByOrder, - OLVColumn sortByColumn, SortOrder sortByOrder, OLVColumn secondaryColumn, SortOrder secondaryOrder) { - + OLVColumn sortByColumn, SortOrder sortByOrder, OLVColumn secondaryColumn, SortOrder secondaryOrder) + { + // If the user tries to group by a non-groupable column, keep the current group by // settings, but use the non-groupable column for sorting - if (!groupByColumn.Groupable && lastGroupingParameters != null) { + if (!groupByColumn.Groupable && lastGroupingParameters != null) + { sortByColumn = groupByColumn; sortByOrder = groupByOrder; groupByColumn = lastGroupingParameters.GroupByColumn; @@ -4134,14 +4495,16 @@ namespace BrightIdeasSoftware /// The list of groups to be created /// This should not change the state of the control. It is possible that the /// groups created will not be used. They may simply be discarded. - protected virtual IList MakeGroups(GroupingParameters parms) { + protected virtual IList MakeGroups(GroupingParameters parms) + { // There is a lot of overlap between this method and FastListGroupingStrategy.MakeGroups() // Any changes made here may need to be reflected there // Separate the list view items into groups, using the group key as the descrimanent NullableDictionary> map = new NullableDictionary>(); - foreach (OLVListItem olvi in parms.ListView.Items) { + foreach (OLVListItem olvi in parms.ListView.Items) + { object key = parms.GroupByColumn.GetGroupKey(olvi.RowObject); if (!map.ContainsKey(key)) map[key] = new List(); @@ -4150,24 +4513,31 @@ namespace BrightIdeasSoftware // Sort the items within each group (unless specifically turned off) OLVColumn sortColumn = parms.SortItemsByPrimaryColumn ? parms.ListView.GetColumn(0) : parms.PrimarySort; - if (sortColumn != null && parms.PrimarySortOrder != SortOrder.None) { - IComparer itemSorter = parms.ItemComparer ?? + if (sortColumn != null && parms.PrimarySortOrder != SortOrder.None) + { + IComparer itemSorter = parms.ItemComparer ?? new ColumnComparer(sortColumn, parms.PrimarySortOrder, parms.SecondarySort, parms.SecondarySortOrder); - foreach (object key in map.Keys) { + foreach (object key in map.Keys) + { map[key].Sort(itemSorter); } } // Make a list of the required groups List groups = new List(); - foreach (object key in map.Keys) { + foreach (object key in map.Keys) + { string title = parms.GroupByColumn.ConvertGroupKeyToTitle(key); - if (!String.IsNullOrEmpty(parms.TitleFormat)) { + if (!String.IsNullOrEmpty(parms.TitleFormat)) + { int count = map[key].Count; string format = (count == 1 ? parms.TitleSingularFormat : parms.TitleFormat); - try { + try + { title = String.Format(format, title, count); - } catch (FormatException) { + } + catch (FormatException) + { title = "Invalid group format: " + format; } } @@ -4192,7 +4562,8 @@ namespace BrightIdeasSoftware /// /// Build/rebuild all the list view items in the list, preserving as much state as is possible /// - public virtual void BuildList() { + public virtual void BuildList() + { if (this.InvokeRequired) this.Invoke(new MethodInvoker(this.BuildList)); else @@ -4211,7 +4582,8 @@ namespace BrightIdeasSoftware /// as previously. /// /// - public virtual void BuildList(bool shouldPreserveState) { + public virtual void BuildList(bool shouldPreserveState) + { if (this.Frozen) return; @@ -4224,7 +4596,8 @@ namespace BrightIdeasSoftware IList previousSelection = new ArrayList(); Object previousFocus = null; - if (shouldPreserveState && this.objects != null) { + if (shouldPreserveState && this.objects != null) + { previousSelection = this.SelectedObjects; OLVListItem focusedItem = this.FocusedItem as OLVListItem; if (focusedItem != null) @@ -4234,15 +4607,18 @@ namespace BrightIdeasSoftware IEnumerable objectsToDisplay = this.FilteredObjects; this.BeginUpdate(); - try { + try + { this.Items.Clear(); this.ListViewItemSorter = null; - if (objectsToDisplay != null) { + if (objectsToDisplay != null) + { // Build a list of all our items and then display them. (Building // a list and then doing one AddRange is about 10-15% faster than individual adds) List itemList = new List(); // use ListViewItem to avoid co-variant conversion - foreach (object rowObject in objectsToDisplay) { + foreach (object rowObject in objectsToDisplay) + { OLVListItem lvi = new OLVListItem(rowObject); this.FillInValues(lvi, rowObject); itemList.Add(lvi); @@ -4250,12 +4626,15 @@ namespace BrightIdeasSoftware this.Items.AddRange(itemList.ToArray()); this.Sort(); - if (shouldPreserveState) { + if (shouldPreserveState) + { this.SelectedObjects = previousSelection; this.FocusedItem = this.ModelToItem(previousFocus); } } - } finally { + } + finally + { this.EndUpdate(); } @@ -4263,7 +4642,8 @@ namespace BrightIdeasSoftware // We can only restore the scroll position after the EndUpdate() because // of caching that the ListView does internally during a BeginUpdate/EndUpdate pair. - if (shouldPreserveState) { + if (shouldPreserveState) + { // Restore the scroll position. TopItemIndex is best, but doesn't work // when the control is grouped. if (this.ShowGroups) @@ -4299,7 +4679,8 @@ namespace BrightIdeasSoftware /// value, bad things happen (the control crashes!). /// /// - protected virtual void ApplyExtendedStyles() { + protected virtual void ApplyExtendedStyles() + { const int LVS_EX_SUBITEMIMAGES = 0x00000002; //const int LVS_EX_TRANSPARENTBKGND = 0x00400000; const int LVS_EX_HEADERINALLVIEWS = 0x02000000; @@ -4320,11 +4701,13 @@ namespace BrightIdeasSoftware /// Give the listview a reasonable size of its tiles, based on the number of lines of /// information that each tile is going to display. /// - public virtual void CalculateReasonableTileSize() { + public virtual void CalculateReasonableTileSize() + { if (this.Columns.Count <= 0) return; - List columns = this.AllColumns.FindAll(delegate(OLVColumn x) { + List columns = this.AllColumns.FindAll(delegate (OLVColumn x) + { return (x.Index == 0) || x.IsTileViewColumn; }); @@ -4339,7 +4722,8 @@ namespace BrightIdeasSoftware /// Rebuild this list for the given view /// /// - public virtual void ChangeToFilteredColumns(View view) { + public virtual void ChangeToFilteredColumns(View view) + { // Store the state this.SuspendSelectionEvents(); IList previousSelection = this.SelectedObjects; @@ -4348,7 +4732,8 @@ namespace BrightIdeasSoftware this.Freeze(); this.Clear(); List columns = this.GetFilteredColumns(view); - if (view == View.Details || this.ShowHeaderInAllViews) { + if (view == View.Details || this.ShowHeaderInAllViews) + { // Make sure all columns have a reasonable LastDisplayIndex for (int index = 0; index < columns.Count; index++) { @@ -4361,13 +4746,13 @@ namespace BrightIdeasSoftware // the last position they were displayed and use that to generate a sequence // we can use for the DisplayIndex values. List columnsInDisplayOrder = new List(columns); - columnsInDisplayOrder.Sort(delegate(OLVColumn x, OLVColumn y) { return (x.LastDisplayIndex - y.LastDisplayIndex); }); + columnsInDisplayOrder.Sort(delegate (OLVColumn x, OLVColumn y) { return (x.LastDisplayIndex - y.LastDisplayIndex); }); int i = 0; foreach (OLVColumn col in columnsInDisplayOrder) col.DisplayIndex = i++; } -// ReSharper disable once CoVariantArrayConversion + // ReSharper disable once CoVariantArrayConversion this.Columns.AddRange(columns.ToArray()); if (view == View.Details || this.ShowHeaderInAllViews) this.ShowSortIndicator(); @@ -4384,7 +4769,8 @@ namespace BrightIdeasSoftware /// Remove all items from this list /// /// This method can safely be called from background threads. - public virtual void ClearObjects() { + public virtual void ClearObjects() + { if (this.InvokeRequired) this.Invoke(new MethodInvoker(this.ClearObjects)); else @@ -4394,7 +4780,8 @@ namespace BrightIdeasSoftware /// /// Reset the memory of which URLs have been visited /// - public virtual void ClearUrlVisited() { + public virtual void ClearUrlVisited() + { this.visitedUrlMap = new Dictionary(); } @@ -4404,7 +4791,8 @@ namespace BrightIdeasSoftware /// Be careful when using this with virtual lists. If the user has selected /// 10,000,000 rows, this method will faithfully try to copy all of them to the clipboard. /// From the user's point of view, your program will appear to have hung. - public virtual void CopySelectionToClipboard() { + public virtual void CopySelectionToClipboard() + { IList selection = this.SelectedObjects; if (selection.Count == 0) return; @@ -4422,7 +4810,8 @@ namespace BrightIdeasSoftware /// /// Copy a text and html representation of the given objects onto the clipboard. /// - public virtual void CopyObjectsToClipboard(IList objectsToCopy) { + public virtual void CopyObjectsToClipboard(IList objectsToCopy) + { if (objectsToCopy.Count == 0) return; @@ -4436,7 +4825,8 @@ namespace BrightIdeasSoftware /// /// Return a html representation of the given objects /// - public virtual string ObjectsToHtml(IList objectsToConvert) { + public virtual string ObjectsToHtml(IList objectsToConvert) + { if (objectsToConvert.Count == 0) return String.Empty; @@ -4447,7 +4837,8 @@ namespace BrightIdeasSoftware /// /// Deselect all rows in the listview /// - public virtual void DeselectAll() { + public virtual void DeselectAll() + { NativeMethods.DeselectAllItems(this); } @@ -4458,11 +4849,15 @@ namespace BrightIdeasSoftware /// /// The item that is before the item that is returned, or null /// A ListViewItem - public virtual OLVListItem GetNextItem(OLVListItem itemToFind) { - if (this.ShowGroups) { + public virtual OLVListItem GetNextItem(OLVListItem itemToFind) + { + if (this.ShowGroups) + { bool isFound = (itemToFind == null); - foreach (ListViewGroup group in this.Groups) { - foreach (OLVListItem olvi in group.Items) { + foreach (ListViewGroup group in this.Groups) + { + foreach (OLVListItem olvi in group.Items) + { if (isFound) return olvi; isFound = (itemToFind == olvi); @@ -4485,11 +4880,13 @@ namespace BrightIdeasSoftware /// sorted list order. But if the list is grouped, the display order is different. /// /// - public virtual OLVListItem GetLastItemInDisplayOrder() { + public virtual OLVListItem GetLastItemInDisplayOrder() + { if (!this.ShowGroups) return this.GetItem(this.GetItemCount() - 1); - - if (this.Groups.Count > 0) { + + if (this.Groups.Count > 0) + { ListViewGroup lastGroup = this.Groups[this.Groups.Count - 1]; if (lastGroup.Items.Count > 0) return (OLVListItem)lastGroup.Items[lastGroup.Items.Count - 1]; @@ -4505,11 +4902,13 @@ namespace BrightIdeasSoftware /// /// /// - public virtual OLVListItem GetNthItemInDisplayOrder(int n) { + public virtual OLVListItem GetNthItemInDisplayOrder(int n) + { if (!this.ShowGroups || this.Groups.Count == 0) return this.GetItem(n); - foreach (ListViewGroup group in this.Groups) { + foreach (ListViewGroup group in this.Groups) + { if (n < group.Items.Count) return (OLVListItem)group.Items[n]; @@ -4526,14 +4925,17 @@ namespace BrightIdeasSoftware /// /// /// - public virtual int GetDisplayOrderOfItemIndex(int itemIndex) { + public virtual int GetDisplayOrderOfItemIndex(int itemIndex) + { if (!this.ShowGroups || this.Groups.Count == 0) return itemIndex; // TODO: This could be optimized int i = 0; - foreach (ListViewGroup lvg in this.Groups) { - foreach (ListViewItem lvi in lvg.Items) { + foreach (ListViewGroup lvg in this.Groups) + { + foreach (ListViewItem lvi in lvg.Items) + { if (lvi.Index == itemIndex) return i; i++; @@ -4550,14 +4952,18 @@ namespace BrightIdeasSoftware /// /// The item that is before the item that is returned /// A ListViewItem - public virtual OLVListItem GetPreviousItem(OLVListItem itemToFind) { - if (this.ShowGroups) { + public virtual OLVListItem GetPreviousItem(OLVListItem itemToFind) + { + if (this.ShowGroups) + { OLVListItem previousItem = null; - foreach (ListViewGroup group in this.Groups) { - foreach (OLVListItem lvi in group.Items) { + foreach (ListViewGroup group in this.Groups) + { + foreach (OLVListItem lvi in group.Items) + { if (lvi == itemToFind) return previousItem; - + previousItem = lvi; } } @@ -4585,9 +4991,12 @@ namespace BrightIdeasSoftware /// /// This method only works on ObjectListViews and FastObjectListViews. /// - public virtual void InsertObjects(int index, ICollection modelObjects) { - if (this.InvokeRequired) { - this.Invoke((MethodInvoker)delegate() { + public virtual void InsertObjects(int index, ICollection modelObjects) + { + if (this.InvokeRequired) + { + this.Invoke((MethodInvoker)delegate () + { this.InsertObjects(index, modelObjects); }); return; @@ -4596,7 +5005,8 @@ namespace BrightIdeasSoftware return; this.BeginUpdate(); - try { + try + { // Give the world a chance to cancel or change the added objects ItemsAddingEventArgs args = new ItemsAddingEventArgs(modelObjects); this.OnItemsAdding(args); @@ -4609,16 +5019,21 @@ namespace BrightIdeasSoftware // If we are filtering the list, there is no way to efficiently // insert the objects, so just put them into our collection and rebuild. - if (this.IsFiltering) { + if (this.IsFiltering) + { index = Math.Max(0, Math.Min(index, ourObjects.Count)); ourObjects.InsertRange(index, modelObjects); this.BuildList(true); - } else { + } + else + { this.ListViewItemSorter = null; index = Math.Max(0, Math.Min(index, this.GetItemCount())); int i = index; - foreach (object modelObject in modelObjects) { - if (modelObject != null) { + foreach (object modelObject in modelObjects) + { + if (modelObject != null) + { ourObjects.Insert(i, modelObject); OLVListItem lvi = new OLVListItem(modelObject); this.FillInValues(lvi, modelObject); @@ -4627,7 +5042,8 @@ namespace BrightIdeasSoftware } } - for (i = index; i < this.GetItemCount(); i++) { + for (i = index; i < this.GetItemCount(); i++) + { OLVListItem lvi = this.GetItem(i); this.SetSubItemImages(lvi.Index, lvi); } @@ -4638,7 +5054,9 @@ namespace BrightIdeasSoftware // Tell the world that the list has changed this.SubscribeNotifications(modelObjects); this.OnItemsChanged(new ItemsChangedEventArgs()); - } finally { + } + finally + { this.EndUpdate(); } } @@ -4648,7 +5066,8 @@ namespace BrightIdeasSoftware /// /// The model object to look for /// Is the row selected - public bool IsSelected(object model) { + public bool IsSelected(object model) + { OLVListItem item = this.ModelToItem(model); return item != null && item.Selected; } @@ -4658,7 +5077,8 @@ namespace BrightIdeasSoftware /// /// The string to be consider /// Has it been visited - public virtual bool IsUrlVisited(string url) { + public virtual bool IsUrlVisited(string url) + { return this.visitedUrlMap.ContainsKey(url); } @@ -4667,7 +5087,8 @@ namespace BrightIdeasSoftware /// /// Horizontal delta /// Vertical delta - public void LowLevelScroll(int dx, int dy) { + public void LowLevelScroll(int dx, int dy) + { NativeMethods.Scroll(this, dx, dy); } @@ -4676,9 +5097,10 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public Point LowLevelScrollPosition + public Point LowLevelScrollPosition { - get { + get + { return new Point(NativeMethods.GetScrollPosition(this, true), NativeMethods.GetScrollPosition(this, false)); } } @@ -4688,7 +5110,8 @@ namespace BrightIdeasSoftware /// /// The url to be remembered /// This does not cause the control be redrawn - public virtual void MarkUrlVisited(string url) { + public virtual void MarkUrlVisited(string url) + { this.visitedUrlMap[url] = true; } @@ -4698,7 +5121,8 @@ namespace BrightIdeasSoftware /// This operation only makes sense on non-grouped ObjectListViews. /// /// - public virtual void MoveObjects(int index, ICollection modelObjects) { + public virtual void MoveObjects(int index, ICollection modelObjects) + { // We are going to remove all the given objects from our list // and then insert them at the given location @@ -4706,10 +5130,13 @@ namespace BrightIdeasSoftware ArrayList ourObjects = ObjectListView.EnumerableToArray(this.Objects, false); List indicesToRemove = new List(); - foreach (object modelObject in modelObjects) { - if (modelObject != null) { + foreach (object modelObject in modelObjects) + { + if (modelObject != null) + { int i = this.IndexOf(modelObject); - if (i >= 0) { + if (i >= 0) + { indicesToRemove.Add(i); ourObjects.Remove(modelObject); if (i <= index) @@ -4722,13 +5149,17 @@ namespace BrightIdeasSoftware // deletes don't change the index of later ones indicesToRemove.Sort(); indicesToRemove.Reverse(); - try { + try + { this.BeginUpdate(); - foreach (int i in indicesToRemove) { + foreach (int i in indicesToRemove) + { this.Items.RemoveAt(i); } this.InsertObjects(index, modelObjects); - } finally { + } + finally + { this.EndUpdate(); } } @@ -4739,12 +5170,16 @@ namespace BrightIdeasSoftware /// /// /// - new public ListViewHitTestInfo HitTest(int x, int y) { + new public ListViewHitTestInfo HitTest(int x, int y) + { // Everything costs something. Playing with the layout of the header can cause problems // with the hit testing. If the header shrinks, the underlying control can throw a tantrum. - try { + try + { return base.HitTest(x, y); - } catch (ArgumentOutOfRangeException) { + } + catch (ArgumentOutOfRangeException) + { return new ListViewHitTestInfo(null, null, ListViewHitTestLocations.None); } } @@ -4756,7 +5191,8 @@ namespace BrightIdeasSoftware /// /// /// - protected OlvListViewHitTestInfo LowLevelHitTest(int x, int y) { + protected OlvListViewHitTestInfo LowLevelHitTest(int x, int y) + { // If it's not even in the control, don't bother with anything else if (!this.ClientRectangle.Contains(x, y)) @@ -4764,7 +5200,7 @@ namespace BrightIdeasSoftware // Is the point over the header? OlvListViewHitTestInfo.HeaderHitTestInfo headerHitTestInfo = this.HeaderControl.HitTest(x, y); - if (headerHitTestInfo != null) + if (headerHitTestInfo != null) return new OlvListViewHitTestInfo(this, headerHitTestInfo.ColumnIndex, headerHitTestInfo.IsOverCheckBox, headerHitTestInfo.OverDividerIndex); // Call the native hit test method, which is a little confusing. @@ -4787,13 +5223,20 @@ namespace BrightIdeasSoftware // - if the point is over a group, the returned value is the *id* of the hit group. // - if the point is not over a group, the returned value is list view item index. OLVGroup group = null; - if (this.ShowGroups && this.OLVGroups != null) { - if (this.VirtualMode) { + if (this.ShowGroups && this.OLVGroups != null) + { + if (this.VirtualMode) + { group = lParam.iGroup >= 0 && lParam.iGroup < this.OLVGroups.Count ? this.OLVGroups[lParam.iGroup] : null; - } else { - if (isGroupHit) { - foreach (OLVGroup olvGroup in this.OLVGroups) { - if (olvGroup.GroupId == index) { + } + else + { + if (isGroupHit) + { + foreach (OLVGroup olvGroup in this.OLVGroups) + { + if (olvGroup.GroupId == index) + { group = olvGroup; break; } @@ -4813,7 +5256,8 @@ namespace BrightIdeasSoftware /// /// /// An information block about what is under the point - public virtual OlvListViewHitTestInfo OlvHitTest(int x, int y) { + public virtual OlvListViewHitTestInfo OlvHitTest(int x, int y) + { OlvListViewHitTestInfo hti = this.LowLevelHitTest(x, y); // There is a bug/"feature" of the ListView concerning hit testing. @@ -4842,12 +5286,14 @@ namespace BrightIdeasSoftware // Are we in the buggy context? Details view, not full row select, and // failing to find anything - if (hti.Item == null && !this.FullRowSelect && this.View == View.Details) { + if (hti.Item == null && !this.FullRowSelect && this.View == View.Details) + { // Is the point within the column 0? If it is, maybe it should have been a hit. // Let's test slightly to the right and then to left of column 0. Hopefully one // of those will hit a subitem Point sides = NativeMethods.GetScrolledColumnSides(this, 0); - if (x >= sides.X && x <= sides.Y) { + if (x >= sides.X && x <= sides.Y) + { // We look for: // - any subitem to the right of cell 0? // - any subitem to the left of cell 0? @@ -4858,7 +5304,8 @@ namespace BrightIdeasSoftware if (hti.Item == null) hti = this.LowLevelHitTest(4, y); - if (hti.Item != null) { + if (hti.Item != null) + { // We hit something! So, the original point must have been in cell 0 hti.ColumnIndex = 0; hti.SubItem = hti.Item.GetSubItem(0); @@ -4882,7 +5329,8 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void CalculateStandardHitTest(OlvListViewHitTestInfo hti, int x, int y) { + protected virtual void CalculateStandardHitTest(OlvListViewHitTestInfo hti, int x, int y) + { // Standard hit test works fine for the primary column if (this.View != View.Details || hti.ColumnIndex == 0 || @@ -4899,12 +5347,15 @@ namespace BrightIdeasSoftware // If there is a checkbox or image there, tag it and exit. Rectangle r = cellBounds; r.Width = this.SmallImageSize.Width; - if (r.Contains(x, y)) { - if (hti.Column.CheckBoxes) { + if (r.Contains(x, y)) + { + if (hti.Column.CheckBoxes) + { hti.HitTestLocation = HitTestLocation.CheckBox; return; } - if (hasImage) { + if (hasImage) + { hti.HitTestLocation = HitTestLocation.Image; return; } @@ -4922,7 +5373,8 @@ namespace BrightIdeasSoftware Size textSize = TextRenderer.MeasureText(hti.SubItem.Text, this.Font, proposedSize, TextFormatFlags.EndEllipsis | TextFormatFlags.SingleLine | TextFormatFlags.NoPrefix); textBounds.Width = textSize.Width; - switch (hti.Column.TextAlign) { + switch (hti.Column.TextAlign) + { case HorizontalAlignment.Center: textBounds.X += (cellBounds.Right - cellBounds.Left - textSize.Width) / 2; break; @@ -4930,7 +5382,8 @@ namespace BrightIdeasSoftware textBounds.X = cellBounds.Right - textSize.Width; break; } - if (textBounds.Contains(x, y)) { + if (textBounds.Contains(x, y)) + { hti.HitTestLocation = HitTestLocation.Text; } } @@ -4942,7 +5395,8 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void CalculateOwnerDrawnHitTest(OlvListViewHitTestInfo hti, int x, int y) { + protected virtual void CalculateOwnerDrawnHitTest(OlvListViewHitTestInfo hti, int x, int y) + { // If the click wasn't on an item, give up if (hti.Item == null) return; @@ -4968,11 +5422,13 @@ namespace BrightIdeasSoftware /// Pause (or unpause) all animations in the list /// /// true to pause, false to unpause - public virtual void PauseAnimations(bool isPause) { - for (int i = 0; i < this.Columns.Count; i++) { + public virtual void PauseAnimations(bool isPause) + { + for (int i = 0; i < this.Columns.Count; i++) + { OLVColumn col = this.GetColumn(i); ImageRenderer renderer = col.Renderer as ImageRenderer; - if (renderer != null) + if (renderer != null) renderer.Paused = isPause; } } @@ -4980,7 +5436,8 @@ namespace BrightIdeasSoftware /// /// Rebuild the columns based upon its current view and column visibility settings /// - public virtual void RebuildColumns() { + public virtual void RebuildColumns() + { this.ChangeToFilteredColumns(this.View); } @@ -4991,9 +5448,10 @@ namespace BrightIdeasSoftware /// See RemoveObjects() for more details /// This method is thread-safe. /// - public virtual void RemoveObject(object modelObject) { + public virtual void RemoveObject(object modelObject) + { if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate() { this.RemoveObject(modelObject); }); + this.Invoke((MethodInvoker)delegate () { this.RemoveObject(modelObject); }); else this.RemoveObjects(new object[] { modelObject }); } @@ -5006,16 +5464,19 @@ namespace BrightIdeasSoftware /// Nulls and model objects that are not in the ListView are silently ignored. /// This method is thread-safe. /// - public virtual void RemoveObjects(ICollection modelObjects) { - if (this.InvokeRequired) { - this.Invoke((MethodInvoker)delegate() { this.RemoveObjects(modelObjects); }); + public virtual void RemoveObjects(ICollection modelObjects) + { + if (this.InvokeRequired) + { + this.Invoke((MethodInvoker)delegate () { this.RemoveObjects(modelObjects); }); return; } if (modelObjects == null) return; this.BeginUpdate(); - try { + try + { // Give the world a chance to cancel or change the added objects ItemsRemovingEventArgs args = new ItemsRemovingEventArgs(modelObjects); this.OnItemsRemoving(args); @@ -5025,13 +5486,15 @@ namespace BrightIdeasSoftware this.TakeOwnershipOfObjects(); ArrayList ourObjects = ObjectListView.EnumerableToArray(this.Objects, false); - foreach (object modelObject in modelObjects) { - if (modelObject != null) { -// ReSharper disable PossibleMultipleEnumeration + foreach (object modelObject in modelObjects) + { + if (modelObject != null) + { + // ReSharper disable PossibleMultipleEnumeration int i = ourObjects.IndexOf(modelObject); if (i >= 0) ourObjects.RemoveAt(i); -// ReSharper restore PossibleMultipleEnumeration + // ReSharper restore PossibleMultipleEnumeration i = this.IndexOf(modelObject); if (i >= 0) this.Items.RemoveAt(i); @@ -5042,7 +5505,9 @@ namespace BrightIdeasSoftware // Tell the world that the list has changed this.UnsubscribeNotifications(modelObjects); this.OnItemsChanged(new ItemsChangedEventArgs()); - } finally { + } + finally + { this.EndUpdate(); } } @@ -5050,7 +5515,8 @@ namespace BrightIdeasSoftware /// /// Select all rows in the listview /// - public virtual void SelectAll() { + public virtual void SelectAll() + { NativeMethods.SelectAllItems(this); } @@ -5078,7 +5544,8 @@ namespace BrightIdeasSoftware /// Setting this clears any background image. /// /// The image to be drawn. If null, any existing image will be removed. - public void SetNativeBackgroundWatermark(Image image) { + public void SetNativeBackgroundWatermark(Image image) + { NativeMethods.SetBackgroundImage(this, image, true, false, 0, 0); } @@ -5097,7 +5564,8 @@ namespace BrightIdeasSoftware /// The image to be drawn. If null, any existing image will be removed. /// The horizontal percentage where the image will be placed. 0 is absolute left, 100 is absolute right. /// The vertical percentage where the image will be placed. - public void SetNativeBackgroundImage(Image image, int xOffset, int yOffset) { + public void SetNativeBackgroundImage(Image image, int xOffset, int yOffset) + { NativeMethods.SetBackgroundImage(this, image, false, false, xOffset, yOffset); } @@ -5110,7 +5578,8 @@ namespace BrightIdeasSoftware /// are understood before using the method. /// /// The image to be drawn. If null, any existing image will be removed. - public void SetNativeBackgroundTiledImage(Image image) { + public void SetNativeBackgroundTiledImage(Image image) + { NativeMethods.SetBackgroundImage(this, image, false, true, 0, 0); } @@ -5120,7 +5589,8 @@ namespace BrightIdeasSoftware /// This method can safely be called from background threads. /// The list is updated immediately /// The objects to be displayed - public virtual void SetObjects(IEnumerable collection) { + public virtual void SetObjects(IEnumerable collection) + { this.SetObjects(collection, false); } @@ -5131,8 +5601,10 @@ namespace BrightIdeasSoftware /// The list is updated immediately /// The objects to be displayed /// Should the state of the list be preserved as far as is possible. - public virtual void SetObjects(IEnumerable collection, bool preserveState) { - if (this.InvokeRequired) { + public virtual void SetObjects(IEnumerable collection, bool preserveState) + { + if (this.InvokeRequired) + { this.Invoke((MethodInvoker)delegate { this.SetObjects(collection, preserveState); }); return; } @@ -5167,9 +5639,10 @@ namespace BrightIdeasSoftware /// This method will cause the list to be resorted. /// This method only works on ObjectListViews and FastObjectListViews. /// - public virtual void UpdateObject(object modelObject) { + public virtual void UpdateObject(object modelObject) + { if (this.InvokeRequired) - this.Invoke((MethodInvoker)delegate() { this.UpdateObject(modelObject); }); + this.Invoke((MethodInvoker)delegate () { this.UpdateObject(modelObject); }); else this.UpdateObjects(new object[] { modelObject }); } @@ -5185,31 +5658,38 @@ namespace BrightIdeasSoftware /// This method is thread-safe. /// This method only works on ObjectListViews and FastObjectListViews. /// - public virtual void UpdateObjects(ICollection modelObjects) { - if (this.InvokeRequired) { - this.Invoke((MethodInvoker)delegate() { this.UpdateObjects(modelObjects); }); + public virtual void UpdateObjects(ICollection modelObjects) + { + if (this.InvokeRequired) + { + this.Invoke((MethodInvoker)delegate () { this.UpdateObjects(modelObjects); }); return; } if (modelObjects == null || modelObjects.Count == 0) return; this.BeginUpdate(); - try { + try + { this.UnsubscribeNotifications(modelObjects); ArrayList objectsToAdd = new ArrayList(); this.TakeOwnershipOfObjects(); ArrayList ourObjects = ObjectListView.EnumerableToArray(this.Objects, false); - foreach (object modelObject in modelObjects) { - if (modelObject != null) { + foreach (object modelObject in modelObjects) + { + if (modelObject != null) + { int i = ourObjects.IndexOf(modelObject); - if (i < 0) + if (i < 0) objectsToAdd.Add(modelObject); - else { + else + { ourObjects[i] = modelObject; OLVListItem olvi = this.ModelToItem(modelObject); - if (olvi != null) { + if (olvi != null) + { olvi.RowObject = modelObject; this.RefreshItem(olvi); } @@ -5224,7 +5704,8 @@ namespace BrightIdeasSoftware this.SubscribeNotifications(modelObjects); this.OnItemsChanged(new ItemsChangedEventArgs()); } - finally { + finally + { this.EndUpdate(); } } @@ -5236,7 +5717,8 @@ namespace BrightIdeasSoftware /// /// This does nothing if UseNotifyPropertyChanged is false. /// - protected virtual void UpdateNotificationSubscriptions(IEnumerable collection) { + protected virtual void UpdateNotificationSubscriptions(IEnumerable collection) + { if (!this.UseNotifyPropertyChanged) return; @@ -5263,9 +5745,11 @@ namespace BrightIdeasSoftware [Category("ObjectListView"), Description("Should ObjectListView listen for property changed events on the model objects?"), DefaultValue(false)] - public bool UseNotifyPropertyChanged { + public bool UseNotifyPropertyChanged + { get { return this.useNotifyPropertyChanged; } - set { + set + { if (this.useNotifyPropertyChanged == value) return; this.useNotifyPropertyChanged = value; @@ -5281,12 +5765,15 @@ namespace BrightIdeasSoftware /// Subscribe to INotifyPropertyChanges on the given collection of objects. /// /// - protected void SubscribeNotifications(IEnumerable models) { + protected void SubscribeNotifications(IEnumerable models) + { if (!this.UseNotifyPropertyChanged || models == null) return; - foreach (object x in models) { + foreach (object x in models) + { INotifyPropertyChanged notifier = x as INotifyPropertyChanged; - if (notifier != null && !subscribedModels.ContainsKey(notifier)) { + if (notifier != null && !subscribedModels.ContainsKey(notifier)) + { notifier.PropertyChanged += HandleModelOnPropertyChanged; subscribedModels[notifier] = notifier; } @@ -5298,16 +5785,23 @@ namespace BrightIdeasSoftware /// If the given collection is null, unsubscribe from all current subscriptions /// /// - protected void UnsubscribeNotifications(IEnumerable models) { - if (models == null) { - foreach (INotifyPropertyChanged notifier in this.subscribedModels.Keys) { + protected void UnsubscribeNotifications(IEnumerable models) + { + if (models == null) + { + foreach (INotifyPropertyChanged notifier in this.subscribedModels.Keys) + { notifier.PropertyChanged -= HandleModelOnPropertyChanged; } subscribedModels = new Hashtable(); - } else { - foreach (object x in models) { + } + else + { + foreach (object x in models) + { INotifyPropertyChanged notifier = x as INotifyPropertyChanged; - if (notifier != null) { + if (notifier != null) + { notifier.PropertyChanged -= HandleModelOnPropertyChanged; subscribedModels.Remove(notifier); } @@ -5315,7 +5809,8 @@ namespace BrightIdeasSoftware } } - private void HandleModelOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) { + private void HandleModelOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) + { // System.Diagnostics.Debug.WriteLine(String.Format("PropertyChanged: '{0}' on '{1}", propertyChangedEventArgs.PropertyName, sender)); this.RefreshObject(sender); } @@ -5345,7 +5840,8 @@ namespace BrightIdeasSoftware /// /// /// A byte array representing the state of the ObjectListView - public virtual byte[] SaveState() { + public virtual byte[] SaveState() + { ObjectListViewState olvState = new ObjectListViewState(); olvState.VersionNumber = 1; olvState.NumberOfColumns = this.AllColumns.Count; @@ -5363,14 +5859,16 @@ namespace BrightIdeasSoftware if (this.AllColumns.Count > 0 && this.AllColumns[0].LastDisplayIndex == -1) this.RememberDisplayIndicies(); - foreach (OLVColumn column in this.AllColumns) { + foreach (OLVColumn column in this.AllColumns) + { olvState.ColumnIsVisible.Add(column.IsVisible); olvState.ColumnDisplayIndicies.Add(column.LastDisplayIndex); olvState.ColumnWidths.Add(column.Width); } // Now that we have stored our state, convert it to a byte array - using (MemoryStream ms = new MemoryStream()) { + using (MemoryStream ms = new MemoryStream()) + { BinaryFormatter serializer = new BinaryFormatter(); serializer.AssemblyFormat = FormatterAssemblyStyle.Simple; serializer.Serialize(ms, olvState); @@ -5384,35 +5882,44 @@ namespace BrightIdeasSoftware /// /// A byte array returned from SaveState() /// Returns true if the state was restored - public virtual bool RestoreState(byte[] state) { - using (MemoryStream ms = new MemoryStream(state)) { + public virtual bool RestoreState(byte[] state) + { + using (MemoryStream ms = new MemoryStream(state)) + { BinaryFormatter deserializer = new BinaryFormatter(); ObjectListViewState olvState; - try { + try + { olvState = deserializer.Deserialize(ms) as ObjectListViewState; - } catch (System.Runtime.Serialization.SerializationException) { + } + catch (System.Runtime.Serialization.SerializationException) + { return false; } // The number of columns has changed. We have no way to match old // columns to the new ones, so we just give up. if (olvState == null || olvState.NumberOfColumns != this.AllColumns.Count) return false; - if (olvState.SortColumn == -1) { + if (olvState.SortColumn == -1) + { this.PrimarySortColumn = null; this.PrimarySortOrder = SortOrder.None; - } else { + } + else + { this.PrimarySortColumn = this.AllColumns[olvState.SortColumn]; this.PrimarySortOrder = olvState.LastSortOrder; } - for (int i = 0; i < olvState.NumberOfColumns; i++) { + for (int i = 0; i < olvState.NumberOfColumns; i++) + { OLVColumn column = this.AllColumns[i]; column.Width = (int)olvState.ColumnWidths[i]; column.IsVisible = (bool)olvState.ColumnIsVisible[i]; column.LastDisplayIndex = (int)olvState.ColumnDisplayIndicies[i]; } -// ReSharper disable RedundantCheckBeforeAssignment + // ReSharper disable RedundantCheckBeforeAssignment if (olvState.IsShowingGroups != this.ShowGroups) -// ReSharper restore RedundantCheckBeforeAssignment + // ReSharper restore RedundantCheckBeforeAssignment this.ShowGroups = olvState.IsShowingGroups; if (this.View == olvState.CurrentView) this.RebuildColumns(); @@ -5429,19 +5936,19 @@ namespace BrightIdeasSoftware [Serializable] internal class ObjectListViewState { -// ReSharper disable NotAccessedField.Global + // ReSharper disable NotAccessedField.Global public int VersionNumber = 1; -// ReSharper restore NotAccessedField.Global + // ReSharper restore NotAccessedField.Global public int NumberOfColumns = 1; public View CurrentView; public int SortColumn = -1; public bool IsShowingGroups; public SortOrder LastSortOrder = SortOrder.None; -// ReSharper disable FieldCanBeMadeReadOnly.Global + // ReSharper disable FieldCanBeMadeReadOnly.Global public ArrayList ColumnIsVisible = new ArrayList(); public ArrayList ColumnDisplayIndicies = new ArrayList(); public ArrayList ColumnWidths = new ArrayList(); -// ReSharper restore FieldCanBeMadeReadOnly.Global + // ReSharper restore FieldCanBeMadeReadOnly.Global } #endregion @@ -5453,7 +5960,8 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void HandleApplicationIdle(object sender, EventArgs e) { + protected virtual void HandleApplicationIdle(object sender, EventArgs e) + { // Remove the handler before triggering the event Application.Idle -= new EventHandler(HandleApplicationIdle); this.hasIdleHandler = false; @@ -5466,7 +5974,8 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void HandleApplicationIdleResizeColumns(object sender, EventArgs e) { + protected virtual void HandleApplicationIdleResizeColumns(object sender, EventArgs e) + { // Remove the handler before triggering the event Application.Idle -= new EventHandler(this.HandleApplicationIdleResizeColumns); this.hasResizeColumnsHandler = false; @@ -5479,11 +5988,13 @@ namespace BrightIdeasSoftware /// /// /// True if the event was completely handled - protected virtual bool HandleBeginScroll(ref Message m) { + protected virtual bool HandleBeginScroll(ref Message m) + { //System.Diagnostics.Debug.WriteLine("LVN_BEGINSCROLL"); NativeMethods.NMLVSCROLL nmlvscroll = (NativeMethods.NMLVSCROLL)m.GetLParam(typeof(NativeMethods.NMLVSCROLL)); - if (nmlvscroll.dx != 0) { + if (nmlvscroll.dx != 0) + { int scrollPositionH = NativeMethods.GetScrollPosition(this, true); ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.EndScroll, scrollPositionH - nmlvscroll.dx, scrollPositionH, ScrollOrientation.HorizontalScroll); this.OnScroll(args); @@ -5492,7 +6003,8 @@ namespace BrightIdeasSoftware if (this.GetItemCount() == 0) this.Invalidate(); } - if (nmlvscroll.dy != 0) { + if (nmlvscroll.dy != 0) + { int scrollPositionV = NativeMethods.GetScrollPosition(this, false); ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.EndScroll, scrollPositionV - nmlvscroll.dy, scrollPositionV, ScrollOrientation.VerticalScroll); this.OnScroll(args); @@ -5506,7 +6018,8 @@ namespace BrightIdeasSoftware /// /// /// True if the event was completely handled - protected virtual bool HandleEndScroll(ref Message m) { + protected virtual bool HandleEndScroll(ref Message m) + { //System.Diagnostics.Debug.WriteLine("LVN_BEGINSCROLL"); // There is a bug in ListView under XP that causes the gridlines to be incorrectly scrolled @@ -5514,7 +6027,8 @@ namespace BrightIdeasSoftware // KB 813791, but I couldn't find it anywhere. You can follow this thread to see the discussion // http://www.ureader.com/msg/1484143.aspx - if (!ObjectListView.IsVistaOrLater && ObjectListView.IsLeftMouseDown && this.GridLines) { + if (!ObjectListView.IsVistaOrLater && ObjectListView.IsLeftMouseDown && this.GridLines) + { this.Invalidate(); this.Update(); } @@ -5527,14 +6041,17 @@ namespace BrightIdeasSoftware /// /// /// True if the event was completely handled - protected virtual bool HandleLinkClick(ref Message m) { + protected virtual bool HandleLinkClick(ref Message m) + { //System.Diagnostics.Debug.WriteLine("HandleLinkClick"); NativeMethods.NMLVLINK nmlvlink = (NativeMethods.NMLVLINK)m.GetLParam(typeof(NativeMethods.NMLVLINK)); // Find the group that was clicked and trigger an event - foreach (OLVGroup x in this.OLVGroups) { - if (x.GroupId == nmlvlink.iSubItem) { + foreach (OLVGroup x in this.OLVGroups) + { + if (x.GroupId == nmlvlink.iSubItem) + { this.OnGroupTaskClicked(new GroupTaskClickedEventArgs(x)); return true; } @@ -5548,9 +6065,11 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void HandleCellToolTipShowing(object sender, ToolTipShowingEventArgs e) { + protected virtual void HandleCellToolTipShowing(object sender, ToolTipShowingEventArgs e) + { this.BuildCellEvent(e, this.PointToClient(Cursor.Position)); - if (e.Item != null) { + if (e.Item != null) + { e.Text = this.GetCellToolTip(e.ColumnIndex, e.RowIndex); this.OnCellToolTip(e); } @@ -5561,7 +6080,8 @@ namespace BrightIdeasSoftware /// /// /// - internal void HeaderToolTipShowingCallback(object sender, ToolTipShowingEventArgs e) { + internal void HeaderToolTipShowingCallback(object sender, ToolTipShowingEventArgs e) + { this.HandleHeaderToolTipShowing(sender, e); } @@ -5570,7 +6090,8 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void HandleHeaderToolTipShowing(object sender, ToolTipShowingEventArgs e) { + protected virtual void HandleHeaderToolTipShowing(object sender, ToolTipShowingEventArgs e) + { e.ColumnIndex = this.HeaderControl.ColumnIndexUnderCursor; if (e.ColumnIndex < 0) return; @@ -5586,7 +6107,8 @@ namespace BrightIdeasSoftware /// /// Event handler for the column click event /// - protected virtual void HandleColumnClick(object sender, ColumnClickEventArgs e) { + protected virtual void HandleColumnClick(object sender, ColumnClickEventArgs e) + { if (!this.PossibleFinishCellEditing()) return; @@ -5597,9 +6119,12 @@ namespace BrightIdeasSoftware this.PrimarySortOrder = SortOrder.Ascending; this.BeginUpdate(); - try { + try + { this.Sort(e.Column); - } finally { + } + finally + { this.EndUpdate(); } } @@ -5614,9 +6139,10 @@ namespace BrightIdeasSoftware /// protected override void WndProc(ref Message m) { - + // System.Diagnostics.Debug.WriteLine(m.Msg); - switch (m.Msg) { + switch (m.Msg) + { case 2: // WM_DESTROY if (!this.HandleDestroy(ref m)) base.WndProc(ref m); @@ -5690,10 +6216,13 @@ namespace BrightIdeasSoftware break; case 0x1000 + 18: // LVM_HITTEST: //System.Diagnostics.Debug.WriteLine("LVM_HITTEST"); - if (this.skipNextHitTest) { + if (this.skipNextHitTest) + { //System.Diagnostics.Debug.WriteLine("SKIPPING LVM_HITTEST"); this.skipNextHitTest = false; - } else { + } + else + { base.WndProc(ref m); } break; @@ -5708,7 +6237,8 @@ namespace BrightIdeasSoftware /// /// The m to be processed /// bool to indicate if the msg has been handled - protected virtual bool HandleChar(ref Message m) { + protected virtual bool HandleChar(ref Message m) + { // Trigger a normal KeyPress event, which listeners can handle if they want. // Handling the event stops ObjectListView's fancy search-by-typing. @@ -5719,7 +6249,8 @@ namespace BrightIdeasSoftware // What character did the user type and was it part of a longer string? char character = (char)m.WParam.ToInt32(); //TODO: Will this work on 64 bit or MBCS? - if (character == (char)Keys.Back) { + if (character == (char)Keys.Back) + { // Backspace forces the next key to be considered the start of a new search this.timeLastCharEvent = 0; return true; @@ -5732,7 +6263,8 @@ namespace BrightIdeasSoftware // If this control is showing checkboxes, we want to ignore single space presses, // since they are used to toggle the selected checkboxes. - if (this.CheckBoxes && this.lastSearchString == " ") { + if (this.GetCheckBoxes() && this.lastSearchString == " ") + { this.timeLastCharEvent = 0; return true; } @@ -5740,12 +6272,14 @@ namespace BrightIdeasSoftware // Where should the search start? int start = 0; ListViewItem focused = this.FocusedItem; - if (focused != null) { + if (focused != null) + { start = this.GetDisplayOrderOfItemIndex(focused.Index); // If the user presses a single key, we search from after the focused item, // being careful not to march past the end of the list - if (this.lastSearchString.Length == 1) { + if (this.lastSearchString.Length == 1) + { start += 1; if (start == this.GetItemCount()) start = 0; @@ -5764,19 +6298,24 @@ namespace BrightIdeasSoftware // Do the actual search int found = this.FindMatchingRow(searchString, start, SearchDirectionHint.Down); - if (found >= 0) { + if (found >= 0) + { // Select and focus on the found item this.BeginUpdate(); - try { + try + { this.SelectedIndices.Clear(); OLVListItem lvi = this.GetNthItemInDisplayOrder(found); - if (lvi != null) { + if (lvi != null) + { if (lvi.Enabled) lvi.Selected = true; lvi.Focused = true; this.EnsureVisible(lvi.Index); } - } finally { + } + finally + { this.EndUpdate(); } } @@ -5784,7 +6323,8 @@ namespace BrightIdeasSoftware // Tell the world that a search has occurred AfterSearchingEventArgs args2 = new AfterSearchingEventArgs(searchString, found); this.OnAfterSearching(args2); - if (!args2.Handled) { + if (!args2.Handled) + { if (found < 0) System.Media.SystemSounds.Beep.Play(); } @@ -5804,7 +6344,8 @@ namespace BrightIdeasSoftware /// /// We want to ignore context menu requests that are triggered by right clicks on the header /// - protected virtual bool HandleContextMenu(ref Message m) { + protected virtual bool HandleContextMenu(ref Message m) + { // Don't try to handle context menu commands at design time. if (this.DesignMode) return false; @@ -5833,7 +6374,8 @@ namespace BrightIdeasSoftware /// /// The message /// True if the message has been handled - protected virtual bool HandleCustomDraw(ref Message m) { + protected virtual bool HandleCustomDraw(ref Message m) + { const int CDDS_PREPAINT = 1; const int CDDS_POSTPAINT = 2; const int CDDS_PREERASE = 3; @@ -5870,7 +6412,8 @@ namespace BrightIdeasSoftware //System.Diagnostics.Debug.WriteLine(String.Format("cd: {0:x}, {1}, {2}", nmcustomdraw.nmcd.dwDrawStage, nmcustomdraw.dwItemType, nmcustomdraw.nmcd.dwItemSpec)); // Ignore drawing of group items - if (nmcustomdraw.dwItemType == 1) { + if (nmcustomdraw.dwItemType == 1) + { // This is the basis of an idea about how to owner draw group headers //nmcustomdraw.clrText = ColorTranslator.ToWin32(Color.DeepPink); @@ -5884,7 +6427,8 @@ namespace BrightIdeasSoftware return true; } - switch (nmcustomdraw.nmcd.dwDrawStage) { + switch (nmcustomdraw.nmcd.dwDrawStage) + { case CDDS_PREPAINT: //System.Diagnostics.Debug.WriteLine("CDDS_PREPAINT"); // Remember which items were drawn during this paint cycle @@ -5912,11 +6456,13 @@ namespace BrightIdeasSoftware // On Vista, we have a different problem. On Vista, the control nests calls // to PREPAINT and POSTPAINT. We only want to draw overlays on the outermost // POSTPAINT. - if (this.prePaintLevel == 0 && (this.isMarqueSelecting || this.isAfterItemPaint)) { + if (this.prePaintLevel == 0 && (this.isMarqueSelecting || this.isAfterItemPaint)) + { this.shouldDoCustomDrawing = false; // Draw our overlays after everything has been drawn - using (Graphics g = Graphics.FromHdc(nmcustomdraw.nmcd.hdc)) { + using (Graphics g = Graphics.FromHdc(nmcustomdraw.nmcd.hdc)) + { this.DrawAllDecorations(g, this.drawnItems); } } @@ -5936,10 +6482,13 @@ namespace BrightIdeasSoftware // .NET's handling of Tile view and let the underlying control // do its stuff. Strangely, if the Tile view is // completely owner drawn, those erasures don't happen. - if (this.View == View.Tile) { + if (this.View == View.Tile) + { if (this.OwnerDraw && this.ItemRenderer != null) base.WndProc(ref m); - } else { + } + else + { base.WndProc(ref m); } @@ -5950,7 +6499,8 @@ namespace BrightIdeasSoftware //System.Diagnostics.Debug.WriteLine("CDDS_ITEMPOSTPAINT"); // Remember which items have been drawn so we can draw any decorations for them // once all other painting is finished - if (this.Columns.Count > 0) { + if (this.Columns.Count > 0) + { OLVListItem olvi = this.GetItem((int)nmcustomdraw.nmcd.dwItemSpec); if (olvi != null) this.drawnItems.Add(olvi); @@ -5973,8 +6523,8 @@ namespace BrightIdeasSoftware // trigger our own DrawSubItem, and then prevent the default processing from occuring. // Are we owner drawing column 0 when it's in any column except 0? - if (!this.OwnerDraw) - return false; + if (!this.OwnerDraw) + return false; int columnIndex = nmcustomdraw.iSubItem; if (columnIndex != 0) @@ -5991,7 +6541,8 @@ namespace BrightIdeasSoftware // OK. We have the error condition, so lets do what the .NET framework should do. // Trigger an event to draw column 0 when it is not at display index 0 - using (Graphics g = Graphics.FromHdc(nmcustomdraw.nmcd.hdc)) { + using (Graphics g = Graphics.FromHdc(nmcustomdraw.nmcd.hdc)) + { // Correctly calculate the bounds of cell 0 Rectangle r = item.GetSubItemBounds(0); @@ -6043,16 +6594,19 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual bool HandleDestroy(ref Message m) { + protected virtual bool HandleDestroy(ref Message m) + { //System.Diagnostics.Debug.WriteLine(String.Format("WM_DESTROY: Disposing={0}, IsDisposed={1}, VirtualMode={2}", Disposing, IsDisposed, VirtualMode)); // Recreate the header control when the listview control is destroyed this.headerControl = null; // When the underlying control is destroyed, we need to recreate and reconfigure its tooltip - if (this.cellToolTip != null) { + if (this.cellToolTip != null) + { this.cellToolTip.PushSettings(); - this.BeginInvoke((MethodInvoker)delegate { + this.BeginInvoke((MethodInvoker)delegate + { this.UpdateCellToolTipHandle(); this.cellToolTip.PopSettings(); }); @@ -6066,7 +6620,8 @@ namespace BrightIdeasSoftware /// /// The m to be processed /// bool to indicate if the msg has been handled - protected virtual bool HandleFindItem(ref Message m) { + protected virtual bool HandleFindItem(ref Message m) + { // NOTE: As far as I can see, this message is never actually sent to the control, making this // method redundant! @@ -6094,7 +6649,8 @@ namespace BrightIdeasSoftware /// The index of the first row that matched, or -1 /// The text comparison is a case-insensitive, prefix match. The search will /// search the every row until a match is found, wrapping at the end if needed. - public virtual int FindMatchingRow(string text, int start, SearchDirectionHint direction) { + public virtual int FindMatchingRow(string text, int start, SearchDirectionHint direction) + { // We also can't do anything if we don't have data int rowCount = this.GetItemCount(); if (rowCount == 0) @@ -6107,11 +6663,14 @@ namespace BrightIdeasSoftware // Do two searches if necessary to find a match. The second search is the wrap-around part of searching int i; - if (direction == SearchDirectionHint.Down) { + if (direction == SearchDirectionHint.Down) + { i = this.FindMatchInRange(text, start, rowCount - 1, column); if (i == -1 && start > 0) i = this.FindMatchInRange(text, 0, start - 1, column); - } else { + } + else + { i = this.FindMatchInRange(text, start, 0, column); if (i == -1 && start != rowCount) i = this.FindMatchInRange(text, rowCount - 1, start + 1, column); @@ -6128,15 +6687,21 @@ namespace BrightIdeasSoftware /// /// /// The index of the matched row, or -1 - protected virtual int FindMatchInRange(string text, int first, int last, OLVColumn column) { - if (first <= last) { - for (int i = first; i <= last; i++) { + protected virtual int FindMatchInRange(string text, int first, int last, OLVColumn column) + { + if (first <= last) + { + for (int i = first; i <= last; i++) + { string data = column.GetStringValue(this.GetNthItemInDisplayOrder(i).RowObject); if (data.StartsWith(text, StringComparison.CurrentCultureIgnoreCase)) return i; } - } else { - for (int i = first; i >= last; i--) { + } + else + { + for (int i = first; i >= last; i--) + { string data = column.GetStringValue(this.GetNthItemInDisplayOrder(i).RowObject); if (data.StartsWith(text, StringComparison.CurrentCultureIgnoreCase)) return i; @@ -6159,12 +6724,14 @@ namespace BrightIdeasSoftware // nmlvgroup.iGroupId, OLVGroup.StateToString(nmlvgroup.uOldState), OLVGroup.StateToString(nmlvgroup.uNewState))); // Ignore state changes that aren't related to selection, focus or collapsedness - const uint INTERESTING_STATES = (uint) (GroupState.LVGS_COLLAPSED | GroupState.LVGS_FOCUSED | GroupState.LVGS_SELECTED); + const uint INTERESTING_STATES = (uint)(GroupState.LVGS_COLLAPSED | GroupState.LVGS_FOCUSED | GroupState.LVGS_SELECTED); if ((nmlvgroup.uOldState & INTERESTING_STATES) == (nmlvgroup.uNewState & INTERESTING_STATES)) return false; - foreach (OLVGroup group in this.OLVGroups) { - if (group.GroupId == nmlvgroup.iGroupId) { + foreach (OLVGroup group in this.OLVGroups) + { + if (group.GroupId == nmlvgroup.iGroupId) + { GroupStateChangedEventArgs args = new GroupStateChangedEventArgs(group, (GroupState)nmlvgroup.uOldState, (GroupState)nmlvgroup.uNewState); this.OnGroupStateChanged(args); break; @@ -6195,10 +6762,12 @@ namespace BrightIdeasSoftware /// /// /// True if the msg has been handled - protected virtual bool HandleKeyDown(ref Message m) { + protected virtual bool HandleKeyDown(ref Message m) + { // If this is a checkbox list, toggle the selected rows when the user presses Space - if (this.CheckBoxes && m.WParam.ToInt32() == (int)Keys.Space && this.SelectedIndices.Count > 0) { + if (this.GetCheckBoxes() && m.WParam.ToInt32() == (int)Keys.Space && this.SelectedIndices.Count > 0) + { this.ToggleSelectedRowCheckBoxes(); return true; } @@ -6218,12 +6787,14 @@ namespace BrightIdeasSoftware int newScrollPositionH = NativeMethods.GetScrollPosition(this, true); int newScrollPositionV = NativeMethods.GetScrollPosition(this, false); - if (scrollPositionH != newScrollPositionH) { + if (scrollPositionH != newScrollPositionH) + { ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.EndScroll, scrollPositionH, newScrollPositionH, ScrollOrientation.HorizontalScroll); this.OnScroll(args); } - if (scrollPositionV != newScrollPositionV) { + if (scrollPositionV != newScrollPositionV) + { ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.EndScroll, scrollPositionV, newScrollPositionV, ScrollOrientation.VerticalScroll); this.OnScroll(args); @@ -6248,13 +6819,15 @@ namespace BrightIdeasSoftware /// If no rows are selected, this method does nothing. /// /// - public void ToggleSelectedRowCheckBoxes() { + public void ToggleSelectedRowCheckBoxes() + { if (this.SelectedIndices.Count == 0) return; Object primaryModel = this.GetItem(this.SelectedIndices[0]).RowObject; this.ToggleCheckObject(primaryModel); CheckState? state = this.GetCheckState(primaryModel); - if (state.HasValue) { + if (state.HasValue) + { foreach (Object x in this.SelectedObjects) this.SetObjectCheckedness(x, state.Value); } @@ -6265,7 +6838,8 @@ namespace BrightIdeasSoftware /// /// The m to be processed /// bool to indicate if the msg has been handled - protected virtual bool HandleLButtonDown(ref Message m) { + protected virtual bool HandleLButtonDown(ref Message m) + { // We have to intercept this low level message rather than the more natural // overridding of OnMouseDown, since ListCtrl's internal mouse down behavior // is to select (or deselect) rows when the mouse is released. We don't @@ -6285,13 +6859,15 @@ namespace BrightIdeasSoftware /// Subclasses can override this to do something unique /// /// True if the message has been handled - protected virtual bool ProcessLButtonDown(OlvListViewHitTestInfo hti) { + protected virtual bool ProcessLButtonDown(OlvListViewHitTestInfo hti) + { if (hti.Item == null) return false; // If the click occurs on a button, ignore it so the row isn't selected - if (hti.HitTestLocation == HitTestLocation.Button) { + if (hti.HitTestLocation == HitTestLocation.Button) + { this.Invalidate(); return true; @@ -6306,7 +6882,8 @@ namespace BrightIdeasSoftware return true; // Did they click a sub item checkbox? - if (hti.Column != null && hti.Column.Index > 0) { + if (hti.Column != null && hti.Column.Index > 0) + { if (hti.Column.IsEditable && hti.Item.Enabled) this.ToggleSubItemCheckBox(hti.RowObject, hti.Column); return true; @@ -6317,9 +6894,11 @@ namespace BrightIdeasSoftware // If they change the checkbox of a selected row, all the rows in the selection // should be given the same state - if (hti.Item.Selected) { + if (hti.Item.Selected) + { CheckState? state = this.GetCheckState(hti.RowObject); - if (state.HasValue) { + if (state.HasValue) + { foreach (Object x in this.SelectedObjects) this.SetObjectCheckedness(x, state.Value); } @@ -6333,7 +6912,8 @@ namespace BrightIdeasSoftware /// /// The m to be processed /// bool to indicate if the msg has been handled - protected virtual bool HandleLButtonUp(ref Message m) { + protected virtual bool HandleLButtonUp(ref Message m) + { if (this.MouseMoveHitTest == null) return false; @@ -6341,11 +6921,14 @@ namespace BrightIdeasSoftware int y = (m.LParam.ToInt32() >> 16) & 0xFFFF; // Did they click an enabled, non-empty button? - if (this.MouseMoveHitTest.HitTestLocation == HitTestLocation.Button) { + if (this.MouseMoveHitTest.HitTestLocation == HitTestLocation.Button) + { // If a button was hit, Item and Column must be non-null - if (this.MouseMoveHitTest.Item.Enabled || this.MouseMoveHitTest.Column.EnableButtonWhenItemIsDisabled) { + if (this.MouseMoveHitTest.Item.Enabled || this.MouseMoveHitTest.Column.EnableButtonWhenItemIsDisabled) + { string buttonText = this.MouseMoveHitTest.Column.GetStringValue(this.MouseMoveHitTest.RowObject); - if (!String.IsNullOrEmpty(buttonText)) { + if (!String.IsNullOrEmpty(buttonText)) + { this.Invalidate(); CellClickEventArgs args = new CellClickEventArgs(); this.BuildCellEvent(args, new Point(x, y), this.MouseMoveHitTest); @@ -6356,7 +6939,8 @@ namespace BrightIdeasSoftware } // Are they trying to expand/collapse a group? - if (this.MouseMoveHitTest.HitTestLocation == HitTestLocation.GroupExpander) { + if (this.MouseMoveHitTest.HitTestLocation == HitTestLocation.GroupExpander) + { if (this.TriggerGroupExpandCollapse(this.MouseMoveHitTest.Group)) return true; } @@ -6384,7 +6968,8 @@ namespace BrightIdeasSoftware /// /// The m to be processed /// bool to indicate if the msg has been handled - protected virtual bool HandleRButtonDown(ref Message m) { + protected virtual bool HandleRButtonDown(ref Message m) + { int x = m.LParam.ToInt32() & 0xFFFF; int y = (m.LParam.ToInt32() >> 16) & 0xFFFF; @@ -6397,7 +6982,8 @@ namespace BrightIdeasSoftware /// Subclasses can override this to do something unique /// /// True if the message has been handled - protected virtual bool ProcessRButtonDown(OlvListViewHitTestInfo hti) { + protected virtual bool ProcessRButtonDown(OlvListViewHitTestInfo hti) + { if (hti.Item == null) return false; @@ -6410,7 +6996,8 @@ namespace BrightIdeasSoftware /// /// The m to be processed /// bool to indicate if the msg has been handled - protected virtual bool HandleLButtonDoubleClick(ref Message m) { + protected virtual bool HandleLButtonDoubleClick(ref Message m) + { int x = m.LParam.ToInt32() & 0xFFFF; int y = (m.LParam.ToInt32() >> 16) & 0xFFFF; @@ -6423,7 +7010,8 @@ namespace BrightIdeasSoftware /// Subclasses can override this to do something unique /// /// True if the message has been handled - protected virtual bool ProcessLButtonDoubleClick(OlvListViewHitTestInfo hti) { + protected virtual bool ProcessLButtonDoubleClick(OlvListViewHitTestInfo hti) + { // If the user double clicked on a checkbox, ignore it return (hti.HitTestLocation == HitTestLocation.CheckBox); @@ -6434,7 +7022,8 @@ namespace BrightIdeasSoftware /// /// The m to be processed /// bool to indicate if the msg has been handled - protected virtual bool HandleRButtonDoubleClick(ref Message m) { + protected virtual bool HandleRButtonDoubleClick(ref Message m) + { int x = m.LParam.ToInt32() & 0xFFFF; int y = (m.LParam.ToInt32() >> 16) & 0xFFFF; @@ -6447,7 +7036,8 @@ namespace BrightIdeasSoftware /// Subclasses can override this to do something unique /// /// True if the message has been handled - protected virtual bool ProcessRButtonDoubleClick(OlvListViewHitTestInfo hti) { + protected virtual bool ProcessRButtonDoubleClick(OlvListViewHitTestInfo hti) + { // If the user double clicked on a checkbox, ignore it return (hti.HitTestLocation == HitTestLocation.CheckBox); @@ -6476,7 +7066,8 @@ namespace BrightIdeasSoftware /// /// The m to be processed /// bool to indicate if the msg has been handled - protected virtual bool HandleReflectNotify(ref Message m) { + protected virtual bool HandleReflectNotify(ref Message m) + { const int NM_CLICK = -2; const int NM_DBLCLK = -3; const int NM_RDBLCLK = -6; @@ -6504,7 +7095,8 @@ namespace BrightIdeasSoftware NativeMethods.NMHDR nmhdr = (NativeMethods.NMHDR)m.GetLParam(typeof(NativeMethods.NMHDR)); //System.Diagnostics.Debug.WriteLine(String.Format("rn: {0}", nmhdr->code)); - switch (nmhdr.code) { + switch (nmhdr.code) + { case NM_CLICK: // The standard ListView does some strange stuff here when the list has checkboxes. // If you shift click on non-primary columns when FullRowSelect is true, the @@ -6558,7 +7150,8 @@ namespace BrightIdeasSoftware case NM_DBLCLK: // The default behavior of a .NET ListView with checkboxes is to toggle the checkbox on // double-click. That's just silly, if you ask me :) - if (this.CheckBoxes) { + if (this.GetCheckBoxes()) + { // How do we make ListView not do that silliness? We could just ignore the message // but the last part of the base code sets up state information, and without that // state, the ListView doesn't trigger MouseDoubleClick events. So we fake a @@ -6572,7 +7165,8 @@ namespace BrightIdeasSoftware case LVN_ITEMCHANGED: //System.Diagnostics.Debug.WriteLine("LVN_ITEMCHANGED"); NativeMethods.NMLISTVIEW nmlistviewPtr2 = (NativeMethods.NMLISTVIEW)m.GetLParam(typeof(NativeMethods.NMLISTVIEW)); - if ((nmlistviewPtr2.uChanged & LVIF_STATE) != 0) { + if ((nmlistviewPtr2.uChanged & LVIF_STATE) != 0) + { CheckState currentValue = this.CalculateCheckState(nmlistviewPtr2.uOldState); CheckState newCheckValue = this.CalculateCheckState(nmlistviewPtr2.uNewState); if (currentValue != newCheckValue) @@ -6589,12 +7183,13 @@ namespace BrightIdeasSoftware if (isSelected) { - // System.Diagnostics.Debug.WriteLine(String.Format("Selected: {0}", nmlistviewPtr2.iItem)); + // System.Diagnostics.Debug.WriteLine(String.Format("Selected: {0}", nmlistviewPtr2.iItem)); bool isShiftDown = (Control.ModifierKeys & Keys.Shift) == Keys.Shift; // -1 indicates that all rows are to be selected -- in fact, they already have been. // We now have to deselect all the disabled objects. - if (nmlistviewPtr2.iItem == -1 || isShiftDown) { + if (nmlistviewPtr2.iItem == -1 || isShiftDown) + { Stopwatch sw = Stopwatch.StartNew(); foreach (object disabledModel in this.DisabledObjects) { @@ -6619,11 +7214,13 @@ namespace BrightIdeasSoftware case LVN_ITEMCHANGING: //System.Diagnostics.Debug.WriteLine("LVN_ITEMCHANGING"); NativeMethods.NMLISTVIEW nmlistviewPtr = (NativeMethods.NMLISTVIEW)m.GetLParam(typeof(NativeMethods.NMLISTVIEW)); - if ((nmlistviewPtr.uChanged & LVIF_STATE) != 0) { + if ((nmlistviewPtr.uChanged & LVIF_STATE) != 0) + { CheckState currentValue = this.CalculateCheckState(nmlistviewPtr.uOldState); CheckState newCheckValue = this.CalculateCheckState(nmlistviewPtr.uNewState); - if (currentValue != newCheckValue) { + if (currentValue != newCheckValue) + { // Prevent the base method from seeing the state change, // since we handled it elsewhere nmlistviewPtr.uChanged &= ~LVIF_STATE; @@ -6643,7 +7240,7 @@ namespace BrightIdeasSoftware isMsgHandled = this.HandleGroupInfo(ref m); break; - //default: + //default: //System.Diagnostics.Debug.WriteLine(String.Format("reflect notify: {0}", nmhdr.code)); //break; } @@ -6652,8 +7249,10 @@ namespace BrightIdeasSoftware } private bool skipNextHitTest; - private CheckState CalculateCheckState(int state) { - switch ((state & 0xf000) >> 12) { + private CheckState CalculateCheckState(int state) + { + switch ((state & 0xf000) >> 12) + { case 1: return CheckState.Unchecked; case 2: @@ -6670,7 +7269,8 @@ namespace BrightIdeasSoftware /// /// The m to be processed /// bool to indicate if the msg has been handled - protected bool HandleNotify(ref Message m) { + protected bool HandleNotify(ref Message m) + { bool isMsgHandled = false; const int NM_CUSTOMDRAW = -12; @@ -6709,7 +7309,8 @@ namespace BrightIdeasSoftware // If we are willing to compile with unsafe code enabled, we can modify the size of the column in place, using the // commented out code below. But without unsafe code, the best we can do is allow the user to drag the column to // any width, and then spring it back to within bounds once they release the mouse button. UI-wise it's very ugly. - switch (nmheader.nhdr.code) { + switch (nmheader.nhdr.code) + { case NM_CUSTOMDRAW: if (!this.OwnerDrawnHeader) @@ -6729,15 +7330,18 @@ namespace BrightIdeasSoftware case HDN_DIVIDERDBLCLICKW: case HDN_BEGINTRACKA: case HDN_BEGINTRACKW: - if (!this.PossibleFinishCellEditing()) { + if (!this.PossibleFinishCellEditing()) + { m.Result = (IntPtr)1; // prevent the change from happening isMsgHandled = true; break; } - if (nmheader.iItem >= 0 && nmheader.iItem < this.Columns.Count) { + if (nmheader.iItem >= 0 && nmheader.iItem < this.Columns.Count) + { OLVColumn column = this.GetColumn(nmheader.iItem); // Space filling columns can't be dragged or double-click resized - if (column.FillsFreeSpace) { + if (column.FillsFreeSpace) + { m.Result = (IntPtr)1; // prevent the change from happening isMsgHandled = true; } @@ -6750,7 +7354,8 @@ namespace BrightIdeasSoftware break; case HDN_TRACKA: case HDN_TRACKW: - if (nmheader.iItem >= 0 && nmheader.iItem < this.Columns.Count) { + if (nmheader.iItem >= 0 && nmheader.iItem < this.Columns.Count) + { NativeMethods.HDITEM hditem = (NativeMethods.HDITEM)Marshal.PtrToStructure(nmheader.pHDITEM, typeof(NativeMethods.HDITEM)); OLVColumn column = this.GetColumn(nmheader.iItem); if (hditem.cxy < column.MinimumWidth) @@ -6764,13 +7369,16 @@ namespace BrightIdeasSoftware case HDN_ITEMCHANGINGA: case HDN_ITEMCHANGINGW: nmheader = (NativeMethods.NMHEADER)m.GetLParam(typeof(NativeMethods.NMHEADER)); - if (nmheader.iItem >= 0 && nmheader.iItem < this.Columns.Count) { + if (nmheader.iItem >= 0 && nmheader.iItem < this.Columns.Count) + { NativeMethods.HDITEM hditem = (NativeMethods.HDITEM)Marshal.PtrToStructure(nmheader.pHDITEM, typeof(NativeMethods.HDITEM)); OLVColumn column = this.GetColumn(nmheader.iItem); // Check the mask to see if the width field is valid, and if it is, make sure it's within range - if ((hditem.mask & 1) == 1) { + if ((hditem.mask & 1) == 1) + { if (hditem.cxy < column.MinimumWidth || - (column.MaximumWidth != -1 && hditem.cxy > column.MaximumWidth)) { + (column.MaximumWidth != -1 && hditem.cxy > column.MaximumWidth)) + { m.Result = (IntPtr)1; // prevent the change from happening isMsgHandled = true; } @@ -6796,9 +7404,9 @@ namespace BrightIdeasSoftware isMsgHandled = this.CellToolTip.HandleGetDispInfo(ref m); break; -// default: -// System.Diagnostics.Debug.WriteLine(String.Format("notify: {0}", nmheader.nhdr.code)); -// break; + // default: + // System.Diagnostics.Debug.WriteLine(String.Format("notify: {0}", nmheader.nhdr.code)); + // break; } return isMsgHandled; @@ -6807,7 +7415,8 @@ namespace BrightIdeasSoftware /// /// Create a ToolTipControl to manage the tooltip control used by the listview control /// - protected virtual void CreateCellToolTip() { + protected virtual void CreateCellToolTip() + { this.cellToolTip = new ToolTipControl(); this.cellToolTip.AssignHandle(NativeMethods.GetTooltipControl(this)); this.cellToolTip.Showing += new EventHandler(HandleCellToolTipShowing); @@ -6819,7 +7428,8 @@ namespace BrightIdeasSoftware /// Update the handle used by our cell tooltip to be the tooltip used by /// the underlying Windows listview control. /// - protected virtual void UpdateCellToolTipHandle() { + protected virtual void UpdateCellToolTipHandle() + { if (this.cellToolTip != null && this.cellToolTip.Handle == IntPtr.Zero) this.cellToolTip.AssignHandle(NativeMethods.GetTooltipControl(this)); } @@ -6829,7 +7439,8 @@ namespace BrightIdeasSoftware /// /// /// Return true if the msg has been handled and nothing further should be done - protected virtual bool HandlePaint(ref Message m) { + protected virtual bool HandlePaint(ref Message m) + { //System.Diagnostics.Debug.WriteLine("> WMPAINT"); // We only want to custom draw the control within WmPaint message and only @@ -6852,7 +7463,8 @@ namespace BrightIdeasSoftware /// /// Perform any steps needed before painting the control /// - protected virtual void HandlePrePaint() { + protected virtual void HandlePrePaint() + { // When we get a WM_PAINT msg, remember the rectangle that is being updated. // We can't get this information later, since the BeginPaint call wipes it out. // this.lastUpdateRectangle = NativeMethods.GetUpdateRect(this); // we no longer need this, but keep the code so we can see it later @@ -6871,7 +7483,8 @@ namespace BrightIdeasSoftware /// /// Perform any steps needed after painting the control /// - protected virtual void HandlePostPaint() { + protected virtual void HandlePostPaint() + { // This message is no longer necessary, but we keep it for compatibility } @@ -6880,11 +7493,13 @@ namespace BrightIdeasSoftware /// /// The m to be processed /// bool to indicate if the msg has been handled - protected virtual bool HandleWindowPosChanging(ref Message m) { + protected virtual bool HandleWindowPosChanging(ref Message m) + { const int SWP_NOSIZE = 1; NativeMethods.WINDOWPOS pos = (NativeMethods.WINDOWPOS)m.GetLParam(typeof(NativeMethods.WINDOWPOS)); - if ((pos.flags & SWP_NOSIZE) == 0) { + if ((pos.flags & SWP_NOSIZE) == 0) + { if (pos.cx < this.Bounds.Width) // only when shrinking // pos.cx is the window width, not the client area width, so we have to subtract the border widths this.ResizeFreeSpaceFillingColumns(pos.cx - (this.Bounds.Width - this.ClientSize.Width)); @@ -6901,12 +7516,13 @@ namespace BrightIdeasSoftware /// The user has right clicked on the column headers. Do whatever is required /// /// Return true if this event has been handle - protected virtual bool HandleHeaderRightClick(int columnIndex) { + protected virtual bool HandleHeaderRightClick(int columnIndex) + { ColumnClickEventArgs eventArgs = new ColumnClickEventArgs(columnIndex); this.OnColumnRightClick(eventArgs); // TODO: Allow users to say they have handled this event - + return this.ShowHeaderRightClickMenu(columnIndex, Cursor.Position); } @@ -6917,9 +7533,11 @@ namespace BrightIdeasSoftware /// can be -1, indicating that the header was clicked outside of a column /// Where should the menu be shown /// True if a menu was displayed - protected virtual bool ShowHeaderRightClickMenu(int columnIndex, Point pt) { + protected virtual bool ShowHeaderRightClickMenu(int columnIndex, Point pt) + { ToolStripDropDown m = this.MakeHeaderRightClickMenu(columnIndex); - if (m.Items.Count > 0) { + if (m.Items.Count > 0) + { m.Show(pt); return true; } @@ -6934,16 +7552,18 @@ namespace BrightIdeasSoftware /// Index of the column that was right clicked. /// This can be negative, which indicates a click outside of any header. /// The toolstrip that should be displayed - protected virtual ToolStripDropDown MakeHeaderRightClickMenu(int columnIndex) { + protected virtual ToolStripDropDown MakeHeaderRightClickMenu(int columnIndex) + { ToolStripDropDown m = new ContextMenuStrip(); if (columnIndex >= 0 && this.UseFiltering && this.ShowFilterMenuOnRightClick) m = this.MakeFilteringMenu(m, columnIndex); - if (columnIndex >= 0 && this.ShowCommandMenuOnRightClick) + if (columnIndex >= 0 && this.ShowCommandMenuOnRightClick) m = this.MakeColumnCommandMenu(m, columnIndex); - if (this.SelectColumnsOnRightClickBehaviour != ColumnSelectBehaviour.None) { + if (this.SelectColumnsOnRightClickBehaviour != ColumnSelectBehaviour.None) + { m = this.MakeColumnSelectMenu(m); } @@ -6955,7 +7575,8 @@ namespace BrightIdeasSoftware /// /// Return true if this event has been handle [Obsolete("Use HandleHeaderRightClick(int) instead")] - protected virtual bool HandleHeaderRightClick() { + protected virtual bool HandleHeaderRightClick() + { return false; } @@ -6965,7 +7586,8 @@ namespace BrightIdeasSoftware /// /// Where should the menu be placed [Obsolete("Use ShowHeaderRightClickMenu instead")] - protected virtual void ShowColumnSelectMenu(Point pt) { + protected virtual void ShowColumnSelectMenu(Point pt) + { ToolStripDropDown m = this.MakeColumnSelectMenu(new ContextMenuStrip()); m.Show(pt); } @@ -6977,9 +7599,11 @@ namespace BrightIdeasSoftware /// /// Where should the menu be placed [Obsolete("Use ShowHeaderRightClickMenu instead")] - protected virtual void ShowColumnCommandMenu(int columnIndex, Point pt) { + protected virtual void ShowColumnCommandMenu(int columnIndex, Point pt) + { ToolStripDropDown m = this.MakeColumnCommandMenu(new ContextMenuStrip(), columnIndex); - if (this.SelectColumnsOnRightClick) { + if (this.SelectColumnsOnRightClick) + { if (m.Items.Count > 0) m.Items.Add(new ToolStripSeparator()); this.MakeColumnSelectMenu(m); @@ -6991,7 +7615,8 @@ namespace BrightIdeasSoftware /// Gets or set the text to be used for the sorting ascending command /// [Category("Labels - ObjectListView"), DefaultValue("Sort ascending by '{0}'"), Localizable(true)] - public string MenuLabelSortAscending { + public string MenuLabelSortAscending + { get { return this.menuLabelSortAscending; } set { this.menuLabelSortAscending = value; } } @@ -7001,7 +7626,8 @@ namespace BrightIdeasSoftware /// /// [Category("Labels - ObjectListView"), DefaultValue("Sort descending by '{0}'"), Localizable(true)] - public string MenuLabelSortDescending { + public string MenuLabelSortDescending + { get { return this.menuLabelSortDescending; } set { this.menuLabelSortDescending = value; } } @@ -7011,7 +7637,8 @@ namespace BrightIdeasSoftware /// /// [Category("Labels - ObjectListView"), DefaultValue("Group by '{0}'"), Localizable(true)] - public string MenuLabelGroupBy { + public string MenuLabelGroupBy + { get { return this.menuLabelGroupBy; } set { this.menuLabelGroupBy = value; } } @@ -7021,7 +7648,8 @@ namespace BrightIdeasSoftware /// /// [Category("Labels - ObjectListView"), DefaultValue("Lock grouping on '{0}'"), Localizable(true)] - public string MenuLabelLockGroupingOn { + public string MenuLabelLockGroupingOn + { get { return this.menuLabelLockGroupingOn; } set { this.menuLabelLockGroupingOn = value; } } @@ -7031,7 +7659,8 @@ namespace BrightIdeasSoftware /// /// [Category("Labels - ObjectListView"), DefaultValue("Unlock grouping from '{0}'"), Localizable(true)] - public string MenuLabelUnlockGroupingOn { + public string MenuLabelUnlockGroupingOn + { get { return this.menuLabelUnlockGroupingOn; } set { this.menuLabelUnlockGroupingOn = value; } } @@ -7041,7 +7670,8 @@ namespace BrightIdeasSoftware /// /// [Category("Labels - ObjectListView"), DefaultValue("Turn off groups"), Localizable(true)] - public string MenuLabelTurnOffGroups { + public string MenuLabelTurnOffGroups + { get { return this.menuLabelTurnOffGroups; } set { this.menuLabelTurnOffGroups = value; } } @@ -7051,7 +7681,8 @@ namespace BrightIdeasSoftware /// /// [Category("Labels - ObjectListView"), DefaultValue("Unsort"), Localizable(true)] - public string MenuLabelUnsort { + public string MenuLabelUnsort + { get { return this.menuLabelUnsort; } set { this.menuLabelUnsort = value; } } @@ -7061,7 +7692,8 @@ namespace BrightIdeasSoftware /// /// [Category("Labels - ObjectListView"), DefaultValue("Columns"), Localizable(true)] - public string MenuLabelColumns { + public string MenuLabelColumns + { get { return this.menuLabelColumns; } set { this.menuLabelColumns = value; } } @@ -7071,7 +7703,8 @@ namespace BrightIdeasSoftware /// /// [Category("Labels - ObjectListView"), DefaultValue("Select Columns..."), Localizable(true)] - public string MenuLabelSelectColumns { + public string MenuLabelSelectColumns + { get { return this.menuLabelSelectColumns; } set { this.menuLabelSelectColumns = value; } } @@ -7093,7 +7726,8 @@ namespace BrightIdeasSoftware /// The menu to which the items will be added. /// /// Return the menu to which the items were added - public virtual ToolStripDropDown MakeColumnCommandMenu(ToolStripDropDown strip, int columnIndex) { + public virtual ToolStripDropDown MakeColumnCommandMenu(ToolStripDropDown strip, int columnIndex) + { OLVColumn column = this.GetColumn(columnIndex); if (column == null) return strip; @@ -7102,21 +7736,28 @@ namespace BrightIdeasSoftware strip.Items.Add(new ToolStripSeparator()); string label = String.Format(this.MenuLabelSortAscending, column.Text); - if (column.Sortable && !String.IsNullOrEmpty(label)) { - strip.Items.Add(label, ObjectListView.SortAscendingImage, (EventHandler)delegate(object sender, EventArgs args) { + if (column.Sortable && !String.IsNullOrEmpty(label)) + { + strip.Items.Add(label, ObjectListView.SortAscendingImage, (EventHandler)delegate (object sender, EventArgs args) + { this.Sort(column, SortOrder.Ascending); }); } label = String.Format(this.MenuLabelSortDescending, column.Text); - if (column.Sortable && !String.IsNullOrEmpty(label)) { - strip.Items.Add(label, ObjectListView.SortDescendingImage, (EventHandler)delegate(object sender, EventArgs args) { + if (column.Sortable && !String.IsNullOrEmpty(label)) + { + strip.Items.Add(label, ObjectListView.SortDescendingImage, (EventHandler)delegate (object sender, EventArgs args) + { this.Sort(column, SortOrder.Descending); }); } - if (this.CanShowGroups) { + if (this.CanShowGroups) + { label = String.Format(this.MenuLabelGroupBy, column.Text); - if (column.Groupable && !String.IsNullOrEmpty(label)) { - strip.Items.Add(label, null, (EventHandler)delegate(object sender, EventArgs args) { + if (column.Groupable && !String.IsNullOrEmpty(label)) + { + strip.Items.Add(label, null, (EventHandler)delegate (object sender, EventArgs args) + { this.ShowGroups = true; this.PrimarySortColumn = column; this.PrimarySortOrder = SortOrder.Ascending; @@ -7124,20 +7765,28 @@ namespace BrightIdeasSoftware }); } } - if (this.ShowGroups) { - if (this.AlwaysGroupByColumn == column) { + if (this.ShowGroups) + { + if (this.AlwaysGroupByColumn == column) + { label = String.Format(this.MenuLabelUnlockGroupingOn, column.Text); - if (!String.IsNullOrEmpty(label)) { - strip.Items.Add(label, null, (EventHandler)delegate(object sender, EventArgs args) { + if (!String.IsNullOrEmpty(label)) + { + strip.Items.Add(label, null, (EventHandler)delegate (object sender, EventArgs args) + { this.AlwaysGroupByColumn = null; this.AlwaysGroupBySortOrder = SortOrder.None; this.BuildList(); }); } - } else { + } + else + { label = String.Format(this.MenuLabelLockGroupingOn, column.Text); - if (column.Groupable && !String.IsNullOrEmpty(label)) { - strip.Items.Add(label, null, (EventHandler)delegate(object sender, EventArgs args) { + if (column.Groupable && !String.IsNullOrEmpty(label)) + { + strip.Items.Add(label, null, (EventHandler)delegate (object sender, EventArgs args) + { this.ShowGroups = true; this.AlwaysGroupByColumn = column; this.AlwaysGroupBySortOrder = SortOrder.Ascending; @@ -7146,16 +7795,22 @@ namespace BrightIdeasSoftware } } label = String.Format(this.MenuLabelTurnOffGroups, column.Text); - if (!String.IsNullOrEmpty(label)) { - strip.Items.Add(label, null, (EventHandler)delegate(object sender, EventArgs args) { + if (!String.IsNullOrEmpty(label)) + { + strip.Items.Add(label, null, (EventHandler)delegate (object sender, EventArgs args) + { this.ShowGroups = false; this.BuildList(); }); } - } else { + } + else + { label = String.Format(this.MenuLabelUnsort, column.Text); - if (column.Sortable && !String.IsNullOrEmpty(label) && this.PrimarySortOrder != SortOrder.None) { - strip.Items.Add(label, null, (EventHandler)delegate(object sender, EventArgs args) { + if (column.Sortable && !String.IsNullOrEmpty(label) && this.PrimarySortOrder != SortOrder.None) + { + strip.Items.Add(label, null, (EventHandler)delegate (object sender, EventArgs args) + { this.Unsort(); }); } @@ -7169,31 +7824,36 @@ namespace BrightIdeasSoftware /// /// The menu to which the items will be added. /// Return the menu to which the items were added - public virtual ToolStripDropDown MakeColumnSelectMenu(ToolStripDropDown strip) { + public virtual ToolStripDropDown MakeColumnSelectMenu(ToolStripDropDown strip) + { System.Diagnostics.Debug.Assert(this.SelectColumnsOnRightClickBehaviour != ColumnSelectBehaviour.None); // Append a separator if the menu isn't empty and the last item isn't already a separator - if (strip.Items.Count > 0 && (!(strip.Items[strip.Items.Count-1] is ToolStripSeparator))) + if (strip.Items.Count > 0 && (!(strip.Items[strip.Items.Count - 1] is ToolStripSeparator))) strip.Items.Add(new ToolStripSeparator()); if (this.AllColumns.Count > 0 && this.AllColumns[0].LastDisplayIndex == -1) this.RememberDisplayIndicies(); - if (this.SelectColumnsOnRightClickBehaviour == ColumnSelectBehaviour.ModelDialog) { - strip.Items.Add(this.MenuLabelSelectColumns, null, delegate(object sender, EventArgs args) { + if (this.SelectColumnsOnRightClickBehaviour == ColumnSelectBehaviour.ModelDialog) + { + strip.Items.Add(this.MenuLabelSelectColumns, null, delegate (object sender, EventArgs args) + { (new ColumnSelectionForm()).OpenOn(this); }); } - if (this.SelectColumnsOnRightClickBehaviour == ColumnSelectBehaviour.Submenu) { + if (this.SelectColumnsOnRightClickBehaviour == ColumnSelectBehaviour.Submenu) + { ToolStripMenuItem menu = new ToolStripMenuItem(this.MenuLabelColumns); menu.DropDownItemClicked += new ToolStripItemClickedEventHandler(this.ColumnSelectMenuItemClicked); strip.Items.Add(menu); this.AddItemsToColumnSelectMenu(menu.DropDownItems); } - if (this.SelectColumnsOnRightClickBehaviour == ColumnSelectBehaviour.InlineMenu) { + if (this.SelectColumnsOnRightClickBehaviour == ColumnSelectBehaviour.InlineMenu) + { strip.ItemClicked += new ToolStripItemClickedEventHandler(this.ColumnSelectMenuItemClicked); strip.Closing += new ToolStripDropDownClosingEventHandler(this.ColumnSelectMenuClosing); this.AddItemsToColumnSelectMenu(strip.Items); @@ -7207,14 +7867,16 @@ namespace BrightIdeasSoftware /// given collection /// /// - protected void AddItemsToColumnSelectMenu(ToolStripItemCollection items) { + protected void AddItemsToColumnSelectMenu(ToolStripItemCollection items) + { // Sort columns by display order List columns = new List(this.AllColumns); - columns.Sort(delegate(OLVColumn x, OLVColumn y) { return (x.LastDisplayIndex - y.LastDisplayIndex); }); + columns.Sort(delegate (OLVColumn x, OLVColumn y) { return (x.LastDisplayIndex - y.LastDisplayIndex); }); // Build menu from sorted columns - foreach (OLVColumn col in columns) { + foreach (OLVColumn col in columns) + { ToolStripMenuItem mi = new ToolStripMenuItem(col.Text); mi.Checked = col.IsVisible; mi.Tag = col; @@ -7226,7 +7888,8 @@ namespace BrightIdeasSoftware } } - private void ColumnSelectMenuItemClicked(object sender, ToolStripItemClickedEventArgs e) { + private void ColumnSelectMenuItemClicked(object sender, ToolStripItemClickedEventArgs e) + { this.contextMenuStaysOpen = false; ToolStripMenuItem menuItemClicked = e.ClickedItem as ToolStripMenuItem; if (menuItemClicked == null) @@ -7241,7 +7904,8 @@ namespace BrightIdeasSoftware } private bool contextMenuStaysOpen; - private void ColumnSelectMenuClosing(object sender, ToolStripDropDownClosingEventArgs e) { + private void ColumnSelectMenuClosing(object sender, ToolStripDropDownClosingEventArgs e) + { e.Cancel = this.contextMenuStaysOpen && e.CloseReason == ToolStripDropDownCloseReason.ItemClicked; this.contextMenuStaysOpen = false; } @@ -7252,7 +7916,8 @@ namespace BrightIdeasSoftware /// /// /// - public virtual ToolStripDropDown MakeFilteringMenu(ToolStripDropDown strip, int columnIndex) { + public virtual ToolStripDropDown MakeFilteringMenu(ToolStripDropDown strip, int columnIndex) + { OLVColumn column = this.GetColumn(columnIndex); if (column == null) return strip; @@ -7268,7 +7933,8 @@ namespace BrightIdeasSoftware /// Override the OnColumnReordered method to do what we want /// /// - protected override void OnColumnReordered(ColumnReorderedEventArgs e) { + protected override void OnColumnReordered(ColumnReorderedEventArgs e) + { base.OnColumnReordered(e); // The internal logic of the .NET code behind a ENDDRAG event means that, @@ -7278,7 +7944,8 @@ namespace BrightIdeasSoftware this.BeginInvoke(new MethodInvoker(this.RememberDisplayIndicies)); } - private void RememberDisplayIndicies() { + private void RememberDisplayIndicies() + { // Remember the display indexes so we can put them back at a later date foreach (OLVColumn x in this.AllColumns) x.LastDisplayIndex = x.DisplayIndex; @@ -7289,8 +7956,10 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void HandleColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e) { - if (this.UpdateSpaceFillingColumnsWhenDraggingColumnDivider && !this.GetColumn(e.ColumnIndex).FillsFreeSpace) { + protected virtual void HandleColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e) + { + if (this.UpdateSpaceFillingColumnsWhenDraggingColumnDivider && !this.GetColumn(e.ColumnIndex).FillsFreeSpace) + { // If the width of a column is increasing, resize any space filling columns allowing the extra // space that the new column width is going to consume int oldWidth = this.GetColumn(e.ColumnIndex).Width; @@ -7306,7 +7975,8 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void HandleColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e) { + protected virtual void HandleColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e) + { if (!this.GetColumn(e.ColumnIndex).FillsFreeSpace) this.ResizeFreeSpaceFillingColumns(); } @@ -7316,33 +7986,39 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void HandleLayout(object sender, LayoutEventArgs e) { + protected virtual void HandleLayout(object sender, LayoutEventArgs e) + { // We have to delay executing the recalculation of the columns, since virtual lists // get terribly confused if we resize the column widths during this event. - if (!this.hasResizeColumnsHandler) { + if (!this.hasResizeColumnsHandler) + { this.hasResizeColumnsHandler = true; this.RunWhenIdle(this.HandleApplicationIdleResizeColumns); } } - private void RunWhenIdle(EventHandler eventHandler) { + private void RunWhenIdle(EventHandler eventHandler) + { Application.Idle += eventHandler; - if (!this.CanUseApplicationIdle) { - SynchronizationContext.Current.Post(delegate(object x) { Application.RaiseIdle(EventArgs.Empty); }, null); + if (!this.CanUseApplicationIdle) + { + SynchronizationContext.Current.Post(delegate (object x) { Application.RaiseIdle(EventArgs.Empty); }, null); } } /// /// Resize our space filling columns so they fill any unoccupied width in the control /// - protected virtual void ResizeFreeSpaceFillingColumns() { + protected virtual void ResizeFreeSpaceFillingColumns() + { this.ResizeFreeSpaceFillingColumns(this.ClientSize.Width); } /// /// Resize our space filling columns so they fill any unoccupied width in the control /// - protected virtual void ResizeFreeSpaceFillingColumns(int freeSpace) { + protected virtual void ResizeFreeSpaceFillingColumns(int freeSpace) + { // It's too confusing to dynamically resize columns at design time. if (this.DesignMode) return; @@ -7353,19 +8029,23 @@ namespace BrightIdeasSoftware // Calculate the free space available int totalProportion = 0; List spaceFillingColumns = new List(); - for (int i = 0; i < this.Columns.Count; i++) { + for (int i = 0; i < this.Columns.Count; i++) + { OLVColumn col = this.GetColumn(i); - if (col.FillsFreeSpace) { + if (col.FillsFreeSpace) + { spaceFillingColumns.Add(col); totalProportion += col.FreeSpaceProportion; - } else + } + else freeSpace -= col.Width; } freeSpace = Math.Max(0, freeSpace); // Any space filling column that would hit it's Minimum or Maximum // width must be treated as a fixed column. - foreach (OLVColumn col in spaceFillingColumns.ToArray()) { + foreach (OLVColumn col in spaceFillingColumns.ToArray()) + { int newWidth = (freeSpace * col.FreeSpaceProportion) / totalProportion; if (col.MinimumWidth != -1 && newWidth < col.MinimumWidth) @@ -7375,7 +8055,8 @@ namespace BrightIdeasSoftware else newWidth = 0; - if (newWidth > 0) { + if (newWidth > 0) + { col.Width = newWidth; freeSpace -= newWidth; totalProportion -= col.FreeSpaceProportion; @@ -7384,8 +8065,9 @@ namespace BrightIdeasSoftware } // Distribute the free space between the columns - foreach (OLVColumn col in spaceFillingColumns) { - col.Width = (freeSpace*col.FreeSpaceProportion)/totalProportion; + foreach (OLVColumn col in spaceFillingColumns) + { + col.Width = (freeSpace * col.FreeSpaceProportion) / totalProportion; } } @@ -7431,7 +8113,8 @@ namespace BrightIdeasSoftware /// Mark the given object as indeterminate check state /// /// The model object to be marked indeterminate - public virtual void CheckIndeterminateObject(object modelObject) { + public virtual void CheckIndeterminateObject(object modelObject) + { this.SetObjectCheckedness(modelObject, CheckState.Indeterminate); } @@ -7439,7 +8122,8 @@ namespace BrightIdeasSoftware /// Mark the given object as checked in the list /// /// The model object to be checked - public virtual void CheckObject(object modelObject) { + public virtual void CheckObject(object modelObject) + { this.SetObjectCheckedness(modelObject, CheckState.Checked); } @@ -7447,7 +8131,8 @@ namespace BrightIdeasSoftware /// Mark the given objects as checked in the list /// /// The model object to be checked - public virtual void CheckObjects(IEnumerable modelObjects) { + public virtual void CheckObjects(IEnumerable modelObjects) + { foreach (object model in modelObjects) this.CheckObject(model); } @@ -7457,7 +8142,8 @@ namespace BrightIdeasSoftware /// /// /// - public virtual void CheckSubItem(object rowObject, OLVColumn column) { + public virtual void CheckSubItem(object rowObject, OLVColumn column) + { if (column == null || rowObject == null || !column.CheckBoxes) return; @@ -7470,7 +8156,8 @@ namespace BrightIdeasSoftware /// /// /// - public virtual void CheckIndeterminateSubItem(object rowObject, OLVColumn column) { + public virtual void CheckIndeterminateSubItem(object rowObject, OLVColumn column) + { if (column == null || rowObject == null || !column.CheckBoxes) return; @@ -7484,7 +8171,8 @@ namespace BrightIdeasSoftware /// The model object whose checkedness is returned /// Is the given object checked? /// If the given object is not in the list, this method returns false. - public virtual bool IsChecked(object modelObject) { + public virtual bool IsChecked(object modelObject) + { return this.GetCheckState(modelObject) == CheckState.Checked; } @@ -7494,7 +8182,8 @@ namespace BrightIdeasSoftware /// The model object whose checkedness is returned /// Is the given object indeterminately checked? /// If the given object is not in the list, this method returns false. - public virtual bool IsCheckedIndeterminate(object modelObject) { + public virtual bool IsCheckedIndeterminate(object modelObject) + { return this.GetCheckState(modelObject) == CheckState.Indeterminate; } @@ -7503,8 +8192,9 @@ namespace BrightIdeasSoftware /// /// /// - public virtual bool IsSubItemChecked(object rowObject, OLVColumn column) { - if (column == null || rowObject == null || !column.CheckBoxes) + public virtual bool IsSubItemChecked(object rowObject, OLVColumn column) + { + if (column == null || rowObject == null || !column.CheckBoxes) return false; return (column.GetCheckState(rowObject) == CheckState.Checked); } @@ -7515,8 +8205,9 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual CheckState? GetCheckState(Object modelObject) { - if (this.CheckStateGetter != null) + protected virtual CheckState? GetCheckState(Object modelObject) + { + if (this.CheckStateGetter != null) return this.CheckStateGetter(modelObject); return this.PersistentCheckBoxes ? this.GetPersistentCheckState(modelObject) : (CheckState?)null; } @@ -7529,8 +8220,9 @@ namespace BrightIdeasSoftware /// /// The check state that was recorded and that should be used to update /// the control. - protected virtual CheckState PutCheckState(Object modelObject, CheckState state) { - if (this.CheckStatePutter != null) + protected virtual CheckState PutCheckState(Object modelObject, CheckState state) + { + if (this.CheckStatePutter != null) return this.CheckStatePutter(modelObject, state); return this.PersistentCheckBoxes ? this.SetPersistentCheckState(modelObject, state) : state; } @@ -7544,7 +8236,8 @@ namespace BrightIdeasSoftware /// /// /// True if the checkedness of the model changed - protected virtual bool SetObjectCheckedness(object modelObject, CheckState state) { + protected virtual bool SetObjectCheckedness(object modelObject, CheckState state) + { if (GetCheckState(modelObject) == state) return false; @@ -7552,7 +8245,8 @@ namespace BrightIdeasSoftware OLVListItem olvi = this.ModelToItem(modelObject); // If we didn't find the given, we still try to record the check state. - if (olvi == null) { + if (olvi == null) + { this.PutCheckState(modelObject, state); return true; } @@ -7578,16 +8272,20 @@ namespace BrightIdeasSoftware /// unchecked -> checked -> indeterminate -> unchecked ... /// /// The model object to be checked - public virtual void ToggleCheckObject(object modelObject) { + public virtual void ToggleCheckObject(object modelObject) + { OLVListItem olvi = this.ModelToItem(modelObject); if (olvi == null) return; CheckState newState = CheckState.Checked; - if (olvi.CheckState == CheckState.Checked) { + if (olvi.CheckState == CheckState.Checked) + { newState = this.TriStateCheckBoxes ? CheckState.Indeterminate : CheckState.Unchecked; - } else { + } + else + { if (olvi.CheckState == CheckState.Indeterminate && this.TriStateCheckBoxes) newState = CheckState.Unchecked; } @@ -7599,7 +8297,8 @@ namespace BrightIdeasSoftware /// /// Obviously, this is only useful if the column actually has a header checkbox. /// - public virtual void ToggleHeaderCheckBox(OLVColumn column) { + public virtual void ToggleHeaderCheckBox(OLVColumn column) + { if (column == null) return; @@ -7607,7 +8306,8 @@ namespace BrightIdeasSoftware ChangeHeaderCheckBoxState(column, newState); } - private void ChangeHeaderCheckBoxState(OLVColumn column, CheckState newState) { + private void ChangeHeaderCheckBoxState(OLVColumn column, CheckState newState) + { // Tell the world the checkbox was clicked HeaderCheckBoxChangingEventArgs args = new HeaderCheckBoxChangingEventArgs(); args.Column = column; @@ -7622,7 +8322,8 @@ namespace BrightIdeasSoftware column.HeaderCheckState = args.NewCheckState; this.HeaderControl.Invalidate(column); - if (column.HeaderCheckBoxUpdatesRowCheckBoxes) { + if (column.HeaderCheckBoxUpdatesRowCheckBoxes) + { if (column.Index == 0) this.UpdateAllPrimaryCheckBoxes(column); else @@ -7632,8 +8333,9 @@ namespace BrightIdeasSoftware Debug.WriteLine(String.Format("PERF - Changing row checkboxes on {2} objects took {0}ms / {1} ticks", sw.ElapsedMilliseconds, sw.ElapsedTicks, this.GetItemCount())); } - private void UpdateAllPrimaryCheckBoxes(OLVColumn column) { - if (!this.CheckBoxes || column.HeaderCheckState == CheckState.Indeterminate) + private void UpdateAllPrimaryCheckBoxes(OLVColumn column) + { + if (!this.GetCheckBoxes() || column.HeaderCheckState == CheckState.Indeterminate) return; if (column.HeaderCheckState == CheckState.Checked) @@ -7642,7 +8344,8 @@ namespace BrightIdeasSoftware UncheckAll(); } - private void UpdateAllSubItemCheckBoxes(OLVColumn column) { + private void UpdateAllSubItemCheckBoxes(OLVColumn column) + { if (!column.CheckBoxes || column.HeaderCheckState == CheckState.Indeterminate) return; @@ -7656,7 +8359,8 @@ namespace BrightIdeasSoftware /// /// /// - public virtual void ToggleSubItemCheckBox(object rowObject, OLVColumn column) { + public virtual void ToggleSubItemCheckBox(object rowObject, OLVColumn column) + { CheckState currentState = column.GetCheckState(rowObject); CheckState newState = CalculateToggledCheckState(currentState, column.TriStateCheckBoxes, false); @@ -7665,7 +8369,8 @@ namespace BrightIdeasSoftware if (args.Canceled) return; - switch (args.NewValue) { + switch (args.NewValue) + { case CheckState.Checked: this.CheckSubItem(rowObject, column); break; @@ -7690,7 +8395,8 @@ namespace BrightIdeasSoftware /// Mark the given object as unchecked in the list /// /// The model object to be unchecked - public virtual void UncheckObject(object modelObject) { + public virtual void UncheckObject(object modelObject) + { this.SetObjectCheckedness(modelObject, CheckState.Unchecked); } @@ -7698,7 +8404,8 @@ namespace BrightIdeasSoftware /// Mark the given objects as unchecked in the list /// /// The model object to be checked - public virtual void UncheckObjects(IEnumerable modelObjects) { + public virtual void UncheckObjects(IEnumerable modelObjects) + { foreach (object model in modelObjects) this.UncheckObject(model); } @@ -7738,7 +8445,8 @@ namespace BrightIdeasSoftware /// /// Index of the column to be returned /// An OLVColumn - public virtual OLVColumn GetColumn(int index) { + public virtual OLVColumn GetColumn(int index) + { return (OLVColumn)this.Columns[index]; } @@ -7747,8 +8455,10 @@ namespace BrightIdeasSoftware /// /// Name of the column to be returned /// An OLVColumn - public virtual OLVColumn GetColumn(string name) { - foreach (ColumnHeader column in this.Columns) { + public virtual OLVColumn GetColumn(string name) + { + foreach (ColumnHeader column in this.Columns) + { if (column.Text == name) return (OLVColumn)column; } @@ -7761,14 +8471,16 @@ namespace BrightIdeasSoftware /// /// Which view are the columns being calculate for? /// A list of columns - public virtual List GetFilteredColumns(View view) { + public virtual List GetFilteredColumns(View view) + { // For both detail and tile view, the first column must be included. Normally, we would // use the ColumnHeader.Index property, but if the header is not currently part of a ListView // that property returns -1. So, we track the index of // the column header, and always include the first header. int index = 0; - return this.AllColumns.FindAll(delegate(OLVColumn x) { + return this.AllColumns.FindAll(delegate (OLVColumn x) + { return (index++ == 0) || x.IsVisible; }); } @@ -7778,7 +8490,8 @@ namespace BrightIdeasSoftware /// /// the number of items in the list /// If a filter is installed, this will return the number of items that match the filter. - public virtual int GetItemCount() { + public virtual int GetItemCount() + { return this.Items.Count; } @@ -7787,10 +8500,11 @@ namespace BrightIdeasSoftware /// /// Index of the item to be returned /// An OLVListItem - public virtual OLVListItem GetItem(int index) { - if (index < 0 || index >= this.GetItemCount()) + public virtual OLVListItem GetItem(int index) + { + if (index < 0 || index >= this.GetItemCount()) return null; - + return (OLVListItem)this.Items[index]; } @@ -7799,7 +8513,8 @@ namespace BrightIdeasSoftware /// /// Index of the model object to be returned /// A model object - public virtual object GetModelObject(int index) { + public virtual object GetModelObject(int index) + { OLVListItem item = this.GetItem(index); return item == null ? null : item.RowObject; } @@ -7811,13 +8526,15 @@ namespace BrightIdeasSoftware /// Y co-ord /// The column under the given point /// The item under the given point. Can be null. - public virtual OLVListItem GetItemAt(int x, int y, out OLVColumn hitColumn) { + public virtual OLVListItem GetItemAt(int x, int y, out OLVColumn hitColumn) + { hitColumn = null; ListViewHitTestInfo info = this.HitTest(x, y); if (info.Item == null) return null; - if (info.SubItem != null) { + if (info.SubItem != null) + { int subItemIndex = info.Item.SubItems.IndexOf(info.SubItem); hitColumn = this.GetColumn(subItemIndex); } @@ -7831,7 +8548,8 @@ namespace BrightIdeasSoftware /// Index of the item to be returned /// Index of the subitem to be returned /// An OLVListSubItem - public virtual OLVListSubItem GetSubItem(int index, int columnIndex) { + public virtual OLVListSubItem GetSubItem(int index, int columnIndex) + { OLVListItem olvi = this.GetItem(index); return olvi == null ? null : olvi.GetSubItem(columnIndex); } @@ -7852,16 +8570,20 @@ namespace BrightIdeasSoftware /// This does not work on virtual lists, since virtual lists don't use ListViewGroups /// for grouping. Use instead. /// - public virtual void EnsureGroupVisible(ListViewGroup lvg) { + public virtual void EnsureGroupVisible(ListViewGroup lvg) + { if (!this.ShowGroups || lvg == null) return; int groupIndex = this.Groups.IndexOf(lvg); - if (groupIndex <= 0) { + if (groupIndex <= 0) + { // There is no easy way to scroll back to the beginning of the list int delta = 0 - NativeMethods.GetScrollPosition(this, false); NativeMethods.Scroll(this, 0, delta); - } else { + } + else + { // Find the display rectangle of the last item in the previous group ListViewGroup previousGroup = this.Groups[groupIndex - 1]; ListViewItem lastItemInGroup = previousGroup.Items[previousGroup.Items.Count - 1]; @@ -7878,7 +8600,8 @@ namespace BrightIdeasSoftware /// Ensure that the given model object is visible /// /// The model object to be revealed - public virtual void EnsureModelVisible(Object modelObject) { + public virtual void EnsureModelVisible(Object modelObject) + { int index = this.IndexOf(modelObject); if (index >= 0) this.EnsureVisible(index); @@ -7889,7 +8612,8 @@ namespace BrightIdeasSoftware /// /// Model object or null [Obsolete("Use SelectedObject property instead of this method")] - public virtual object GetSelectedObject() { + public virtual object GetSelectedObject() + { return this.SelectedObject; } @@ -7898,7 +8622,8 @@ namespace BrightIdeasSoftware /// /// ArrayList [Obsolete("Use SelectedObjects property instead of this method")] - public virtual ArrayList GetSelectedObjects() { + public virtual ArrayList GetSelectedObjects() + { return ObjectListView.EnumerableToArray(this.SelectedObjects, false); } @@ -7909,7 +8634,8 @@ namespace BrightIdeasSoftware /// Model object or null /// Use CheckedObject property instead of this method [Obsolete("Use CheckedObject property instead of this method")] - public virtual object GetCheckedObject() { + public virtual object GetCheckedObject() + { return this.CheckedObject; } @@ -7918,7 +8644,8 @@ namespace BrightIdeasSoftware /// /// Use CheckedObjects property instead of this method [Obsolete("Use CheckedObjects property instead of this method")] - public virtual ArrayList GetCheckedObjects() { + public virtual ArrayList GetCheckedObjects() + { return ObjectListView.EnumerableToArray(this.CheckedObjects, false); } @@ -7927,8 +8654,10 @@ namespace BrightIdeasSoftware /// /// The model object to be found /// The index of the object. -1 means the object was not present - public virtual int IndexOf(Object modelObject) { - for (int i = 0; i < this.GetItemCount(); i++) { + public virtual int IndexOf(Object modelObject) + { + for (int i = 0; i < this.GetItemCount(); i++) + { if (this.GetModelObject(i).Equals(modelObject)) return i; } @@ -7940,7 +8669,8 @@ namespace BrightIdeasSoftware /// /// This method does not resort or regroup the view. It simply updates /// the displayed data of the given item - public virtual void RefreshItem(OLVListItem olvi) { + public virtual void RefreshItem(OLVListItem olvi) + { olvi.UseItemStyleForSubItems = true; olvi.SubItems.Clear(); this.FillInValues(olvi, olvi.RowObject); @@ -7965,7 +8695,8 @@ namespace BrightIdeasSoftware /// use . /// /// - public virtual void RefreshObject(object modelObject) { + public virtual void RefreshObject(object modelObject) + { this.RefreshObjects(new object[] { modelObject }); } @@ -7976,21 +8707,26 @@ namespace BrightIdeasSoftware /// This method does not resort or regroup the view. /// This method can safely be called from background threads. /// - public virtual void RefreshObjects(IList modelObjects) { - if (this.InvokeRequired) { + public virtual void RefreshObjects(IList modelObjects) + { + if (this.InvokeRequired) + { this.Invoke((MethodInvoker)delegate { this.RefreshObjects(modelObjects); }); return; } - foreach (object modelObject in modelObjects) { + foreach (object modelObject in modelObjects) + { OLVListItem olvi = this.ModelToItem(modelObject); - if (olvi != null) { + if (olvi != null) + { this.ReplaceModel(olvi, modelObject); this.RefreshItem(olvi); } } } - private void ReplaceModel(OLVListItem olvi, object newModel) { + private void ReplaceModel(OLVListItem olvi, object newModel) + { if (ReferenceEquals(olvi.RowObject, newModel)) return; @@ -8007,7 +8743,8 @@ namespace BrightIdeasSoftware /// Update the rows that are selected /// /// This method does not resort or regroup the view. - public virtual void RefreshSelectedObjects() { + public virtual void RefreshSelectedObjects() + { foreach (ListViewItem lvi in this.SelectedItems) this.RefreshItem((OLVListItem)lvi); } @@ -8017,7 +8754,8 @@ namespace BrightIdeasSoftware /// /// The object to be selected /// Use the property to deselect all other rows - public virtual void SelectObject(object modelObject) { + public virtual void SelectObject(object modelObject) + { this.SelectObject(modelObject, false); } @@ -8027,9 +8765,11 @@ namespace BrightIdeasSoftware /// The object to be selected /// Should the object be focused as well? /// Use the property to deselect all other rows - public virtual void SelectObject(object modelObject, bool setFocus) { + public virtual void SelectObject(object modelObject, bool setFocus) + { OLVListItem olvi = this.ModelToItem(modelObject); - if (olvi != null && olvi.Enabled) { + if (olvi != null && olvi.Enabled) + { olvi.Selected = true; if (setFocus) olvi.Focused = true; @@ -8040,13 +8780,15 @@ namespace BrightIdeasSoftware /// Select the rows that is displaying any of the given model object. All other rows are deselected. /// /// A collection of model objects - public virtual void SelectObjects(IList modelObjects) { + public virtual void SelectObjects(IList modelObjects) + { this.SelectedIndices.Clear(); if (modelObjects == null) return; - foreach (object modelObject in modelObjects) { + foreach (object modelObject in modelObjects) + { OLVListItem olvi = this.ModelToItem(modelObject); if (olvi != null && olvi.Enabled) olvi.Selected = true; @@ -8068,12 +8810,15 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public virtual bool Frozen { + public virtual bool Frozen + { get { return freezeCount > 0; } - set { + set + { if (value) Freeze(); - else if (freezeCount > 0) { + else if (freezeCount > 0) + { freezeCount = 1; Unfreeze(); } @@ -8085,7 +8830,8 @@ namespace BrightIdeasSoftware /// Freeze the listview so that it no longer updates itself. /// /// Freeze()/Unfreeze() calls nest correctly - public virtual void Freeze() { + public virtual void Freeze() + { if (freezeCount == 0) DoFreeze(); @@ -8098,7 +8844,8 @@ namespace BrightIdeasSoftware /// the contents of the listview will be rebuilt. /// /// Freeze()/Unfreeze() calls nest correctly - public virtual void Unfreeze() { + public virtual void Unfreeze() + { if (freezeCount <= 0) return; @@ -8112,7 +8859,8 @@ namespace BrightIdeasSoftware /// /// Do the actual work required when the listview is frozen /// - protected virtual void DoFreeze() { + protected virtual void DoFreeze() + { this.BeginUpdate(); } @@ -8133,7 +8881,8 @@ namespace BrightIdeasSoftware /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - protected bool SelectionEventsSuspended { + protected bool SelectionEventsSuspended + { get { return this.suspendSelectionEventCount > 0; } } @@ -8143,14 +8892,16 @@ namespace BrightIdeasSoftware /// /// Calls to this method nest correctly. Every call to SuspendSelectionEvents() /// must have a matching ResumeSelectionEvents(). - protected void SuspendSelectionEvents() { + protected void SuspendSelectionEvents() + { this.suspendSelectionEventCount++; } /// /// Resume raising selection events. /// - protected void ResumeSelectionEvents() { + protected void ResumeSelectionEvents() + { Debug.Assert(this.SelectionEventsSuspended, "Mismatched called to ResumeSelectionEvents()"); this.suspendSelectionEventCount--; } @@ -8160,7 +8911,8 @@ namespace BrightIdeasSoftware /// during a using() block. /// /// - protected IDisposable SuspendSelectionEventsDuring() { + protected IDisposable SuspendSelectionEventsDuring() + { return new SuspendSelectionDisposable(this); } @@ -8168,13 +8920,16 @@ namespace BrightIdeasSoftware /// Implementation only class that suspends and resumes selection /// events on instance creation and disposal. /// - private class SuspendSelectionDisposable : IDisposable { - public SuspendSelectionDisposable(ObjectListView objectListView) { + private class SuspendSelectionDisposable : IDisposable + { + public SuspendSelectionDisposable(ObjectListView objectListView) + { this.objectListView = objectListView; this.objectListView.SuspendSelectionEvents(); } - public void Dispose() { + public void Dispose() + { this.objectListView.ResumeSelectionEvents(); } @@ -8188,7 +8943,8 @@ namespace BrightIdeasSoftware /// /// Sort the items by the last sort column and order /// - new public void Sort() { + new public void Sort() + { this.Sort(this.PrimarySortColumn, this.PrimarySortOrder); } @@ -8196,7 +8952,8 @@ namespace BrightIdeasSoftware /// Sort the items in the list view by the values in the given column and the last sort order /// /// The name of the column whose values will be used for the sorting - public virtual void Sort(string columnToSortName) { + public virtual void Sort(string columnToSortName) + { this.Sort(this.GetColumn(columnToSortName), this.PrimarySortOrder); } @@ -8204,7 +8961,8 @@ namespace BrightIdeasSoftware /// Sort the items in the list view by the values in the given column and the last sort order /// /// The index of the column whose values will be used for the sorting - public virtual void Sort(int columnToSortIndex) { + public virtual void Sort(int columnToSortIndex) + { if (columnToSortIndex >= 0 && columnToSortIndex < this.Columns.Count) this.Sort(this.GetColumn(columnToSortIndex), this.PrimarySortOrder); } @@ -8213,10 +8971,14 @@ namespace BrightIdeasSoftware /// Sort the items in the list view by the values in the given column and the last sort order /// /// The column whose values will be used for the sorting - public virtual void Sort(OLVColumn columnToSort) { - if (this.InvokeRequired) { + public virtual void Sort(OLVColumn columnToSort) + { + if (this.InvokeRequired) + { this.Invoke((MethodInvoker)delegate { this.Sort(columnToSort); }); - } else { + } + else + { this.Sort(columnToSort, this.PrimarySortOrder); } } @@ -8231,24 +8993,31 @@ namespace BrightIdeasSoftware /// If ShowGroups is true, the rows will be grouped by the given column. /// If AlwaysGroupsByColumn is not null, the rows will be grouped by that column, /// and the rows within each group will be sorted by the given column. - public virtual void Sort(OLVColumn columnToSort, SortOrder order) { - if (this.InvokeRequired) { + public virtual void Sort(OLVColumn columnToSort, SortOrder order) + { + if (this.InvokeRequired) + { this.Invoke((MethodInvoker)delegate { this.Sort(columnToSort, order); }); - } else { + } + else + { this.DoSort(columnToSort, order); this.PostProcessRows(); } } - private void DoSort(OLVColumn columnToSort, SortOrder order) { + private void DoSort(OLVColumn columnToSort, SortOrder order) + { // Sanity checks if (this.GetItemCount() == 0 || this.Columns.Count == 0) return; // Fill in default values, if the parameters don't make sense - if (this.ShowGroups) { + if (this.ShowGroups) + { columnToSort = columnToSort ?? this.GetColumn(0); - if (order == SortOrder.None) { + if (order == SortOrder.None) + { order = this.Sorting; if (order == SortOrder.None) order = SortOrder.Ascending; @@ -8269,9 +9038,11 @@ namespace BrightIdeasSoftware this.ClearHotItem(); // Finally, do the work of sorting, unless an event handler has already done the sorting for us - if (!args.Handled) { + if (!args.Handled) + { // Sanity checks - if (args.ColumnToSort != null && args.SortOrder != SortOrder.None) { + if (args.ColumnToSort != null && args.SortOrder != SortOrder.None) + { if (this.ShowGroups) this.BuildGroups(args.ColumnToGroupBy, args.GroupByOrder, args.ColumnToSort, args.SortOrder, args.SecondaryColumnToSort, args.SecondarySortOrder); @@ -8301,7 +9072,8 @@ namespace BrightIdeasSoftware /// /// Put a sort indicator next to the text of the sort column /// - public virtual void ShowSortIndicator() { + public virtual void ShowSortIndicator() + { if (this.ShowSortIndicators && this.PrimarySortOrder != SortOrder.None) this.ShowSortIndicator(this.PrimarySortColumn, this.PrimarySortOrder); } @@ -8311,24 +9083,27 @@ namespace BrightIdeasSoftware /// /// The column to be marked /// The sort order in effect on that column - protected virtual void ShowSortIndicator(OLVColumn columnToSort, SortOrder sortOrder) { + protected virtual void ShowSortIndicator(OLVColumn columnToSort, SortOrder sortOrder) + { int imageIndex = -1; - if (!NativeMethods.HasBuiltinSortIndicators()) { + if (!NativeMethods.HasBuiltinSortIndicators()) + { // If we can't use builtin image, we have to make and then locate the index of the // sort indicator we want to use. SortOrder.None doesn't show an image. - if (this.SmallImageList == null || !this.SmallImageList.Images.ContainsKey(SORT_INDICATOR_UP_KEY)) + if (this.GetSmallImageList() == null || !this.GetSmallImageList().Images.ContainsKey(SORT_INDICATOR_UP_KEY)) MakeSortIndicatorImages(); - if (this.SmallImageList != null) + if (this.GetSmallImageList() != null) { string key = sortOrder == SortOrder.Ascending ? SORT_INDICATOR_UP_KEY : SORT_INDICATOR_DOWN_KEY; - imageIndex = this.SmallImageList.Images.IndexOfKey(key); + imageIndex = this.GetSmallImageList().Images.IndexOfKey(key); } } // Set the image for each column - for (int i = 0; i < this.Columns.Count; i++) { + for (int i = 0; i < this.Columns.Count; i++) + { if (columnToSort != null && i == columnToSort.Index) NativeMethods.SetColumnImage(this, i, sortOrder, imageIndex); else @@ -8351,13 +9126,15 @@ namespace BrightIdeasSoftware /// /// If the sort indicator images don't already exist, this method will make and install them /// - protected virtual void MakeSortIndicatorImages() { + protected virtual void MakeSortIndicatorImages() + { // Don't mess with the image list in design mode if (this.DesignMode) return; - ImageList il = this.SmallImageList; - if (il == null) { + ImageList il = this.GetSmallImageList(); + if (il == null) + { il = new ImageList(); il.ImageSize = new Size(16, 16); il.ColorDepth = ColorDepth.Depth32Bit; @@ -8369,24 +9146,27 @@ namespace BrightIdeasSoftware int deltaX = midX - 2; int deltaY = deltaX / 2; - if (il.Images.IndexOfKey(SORT_INDICATOR_UP_KEY) == -1) { + if (il.Images.IndexOfKey(SORT_INDICATOR_UP_KEY) == -1) + { Point pt1 = new Point(midX - deltaX, midY + deltaY); Point pt2 = new Point(midX, midY - deltaY - 1); Point pt3 = new Point(midX + deltaX, midY + deltaY); il.Images.Add(SORT_INDICATOR_UP_KEY, this.MakeTriangleBitmap(il.ImageSize, new Point[] { pt1, pt2, pt3 })); } - if (il.Images.IndexOfKey(SORT_INDICATOR_DOWN_KEY) == -1) { + if (il.Images.IndexOfKey(SORT_INDICATOR_DOWN_KEY) == -1) + { Point pt1 = new Point(midX - deltaX, midY - deltaY); Point pt2 = new Point(midX, midY + deltaY); Point pt3 = new Point(midX + deltaX, midY - deltaY); il.Images.Add(SORT_INDICATOR_DOWN_KEY, this.MakeTriangleBitmap(il.ImageSize, new Point[] { pt1, pt2, pt3 })); } - this.SmallImageList = il; + this.SetSmallImageList(il); } - private Bitmap MakeTriangleBitmap(Size sz, Point[] pts) { + private Bitmap MakeTriangleBitmap(Size sz, Point[] pts) + { Bitmap bm = new Bitmap(sz.Width, sz.Height); Graphics g = Graphics.FromImage(bm); g.FillPolygon(new SolidBrush(Color.Gray), pts); @@ -8396,7 +9176,8 @@ namespace BrightIdeasSoftware /// /// Remove any sorting and revert to the given order of the model objects /// - public virtual void Unsort() { + public virtual void Unsort() + { this.ShowGroups = false; this.PrimarySortColumn = null; this.PrimarySortOrder = SortOrder.None; @@ -8423,10 +9204,12 @@ namespace BrightIdeasSoftware /// Do the actual work of creating the given list of groups /// /// - protected virtual void CreateGroups(IEnumerable groups) { + protected virtual void CreateGroups(IEnumerable groups) + { this.Groups.Clear(); // The group must be added before it is given items, otherwise an exception is thrown (is this documented?) - foreach (OLVGroup group in groups) { + foreach (OLVGroup group in groups) + { group.InsertGroupOldStyle(this); group.SetItemsOldStyle(); } @@ -8440,7 +9223,8 @@ namespace BrightIdeasSoftware /// The item whose subitems are to be corrected /// Cells drawn via BaseRenderer don't need this, but it is needed /// when an owner drawn cell uses DrawDefault=true - protected virtual void CorrectSubItemColors(ListViewItem olvi) { + protected virtual void CorrectSubItemColors(ListViewItem olvi) + { } /// @@ -8448,7 +9232,8 @@ namespace BrightIdeasSoftware /// /// the OLVListItem that is to be stuff with values /// the model object from which values will be taken - protected virtual void FillInValues(OLVListItem lvi, object rowObject) { + protected virtual void FillInValues(OLVListItem lvi, object rowObject) + { if (this.Columns.Count == 0) return; @@ -8465,14 +9250,17 @@ namespace BrightIdeasSoftware lvi.Enabled = !this.IsDisabled(rowObject); // Only Details and Tile views have subitems - switch (this.View) { + switch (this.View) + { case View.Details: - for (int i = 1; i < this.Columns.Count; i++) { + for (int i = 1; i < this.Columns.Count; i++) + { lvi.SubItems.Add(this.MakeSubItem(rowObject, this.GetColumn(i))); } break; case View.Tile: - for (int i = 1; i < this.Columns.Count; i++) { + for (int i = 1; i < this.Columns.Count; i++) + { OLVColumn column = this.GetColumn(i); if (column.IsTileViewColumn) lvi.SubItems.Add(this.MakeSubItem(rowObject, column)); @@ -8481,30 +9269,35 @@ namespace BrightIdeasSoftware } // Should the row be selectable? - if (!lvi.Enabled) { + if (!lvi.Enabled) + { lvi.UseItemStyleForSubItems = false; ApplyRowStyle(lvi, this.DisabledItemStyle ?? ObjectListView.DefaultDisabledItemStyle); } // Set the check state of the row, if we are showing check boxes - if (this.CheckBoxes) { + if (this.GetCheckBoxes()) + { CheckState? state = this.GetCheckState(lvi.RowObject); if (state.HasValue) lvi.CheckState = state.Value; } // Give the RowFormatter a chance to mess with the item - if (this.RowFormatter != null) { + if (this.RowFormatter != null) + { this.RowFormatter(lvi); } } - private OLVListSubItem MakeSubItem(object rowObject, OLVColumn column) { + private OLVListSubItem MakeSubItem(object rowObject, OLVColumn column) + { object cellValue = column.GetValue(rowObject); OLVListSubItem subItem = new OLVListSubItem(cellValue, column.ValueToString(cellValue), column.GetImage(rowObject)); - if (this.UseHyperlinks && column.Hyperlink) { + if (this.UseHyperlinks && column.Hyperlink) + { IsHyperlinkEventArgs args = new IsHyperlinkEventArgs(); args.ListView = this; args.Model = rowObject; @@ -8519,14 +9312,16 @@ namespace BrightIdeasSoftware return subItem; } - private void ApplyHyperlinkStyle(OLVListItem olvi) { + private void ApplyHyperlinkStyle(OLVListItem olvi) + { - for (int i = 0; i < this.Columns.Count; i++) { + for (int i = 0; i < this.Columns.Count; i++) + { OLVListSubItem subItem = olvi.GetSubItem(i); if (subItem == null) continue; OLVColumn column = this.GetColumn(i); - if (column.Hyperlink && !String.IsNullOrEmpty(subItem.Url)) + if (column.Hyperlink && !String.IsNullOrEmpty(subItem.Url)) this.ApplyCellStyle(olvi, i, this.IsUrlVisited(subItem.Url) ? this.HyperlinkStyle.Visited : this.HyperlinkStyle.Normal); } } @@ -8537,7 +9332,8 @@ namespace BrightIdeasSoftware /// /// This method must be called after any .NET call that update the extended styles /// since they seem to erase this setting. - protected virtual void ForceSubItemImagesExStyle() { + protected virtual void ForceSubItemImagesExStyle() + { // Virtual lists can't show subitem images natively, so don't turn on this flag if (!this.VirtualMode) NativeMethods.ForceSubItemImagesExStyle(this); @@ -8549,7 +9345,8 @@ namespace BrightIdeasSoftware /// /// /// Index of the image in the imageList, or -1 - protected virtual int GetActualImageIndex(Object imageSelector) { + protected virtual int GetActualImageIndex(Object imageSelector) + { if (imageSelector == null) return -1; @@ -8557,8 +9354,8 @@ namespace BrightIdeasSoftware return (int)imageSelector; String imageSelectorAsString = imageSelector as String; - if (imageSelectorAsString != null && this.SmallImageList != null) - return this.SmallImageList.Images.IndexOfKey(imageSelectorAsString); + if (imageSelectorAsString != null && this.GetSmallImageList() != null) + return this.GetSmallImageList().Images.IndexOfKey(imageSelectorAsString); return -1; } @@ -8568,7 +9365,8 @@ namespace BrightIdeasSoftware /// /// The column index whose tool tip is to be fetched /// A string or null if no tool tip is to be shown - public virtual String GetHeaderToolTip(int columnIndex) { + public virtual String GetHeaderToolTip(int columnIndex) + { OLVColumn column = this.GetColumn(columnIndex); if (column == null) return null; @@ -8584,12 +9382,14 @@ namespace BrightIdeasSoftware /// The column index whose tool tip is to be fetched /// The row index whose tool tip is to be fetched /// A string or null if no tool tip is to be shown - public virtual String GetCellToolTip(int columnIndex, int rowIndex) { + public virtual String GetCellToolTip(int columnIndex, int rowIndex) + { if (this.CellToolTipGetter != null) return this.CellToolTipGetter(this.GetColumn(columnIndex), this.GetModelObject(rowIndex)); // Show the URL in the tooltip if it's different to the text - if (columnIndex >= 0) { + if (columnIndex >= 0) + { OLVListSubItem subItem = this.GetSubItem(rowIndex, columnIndex); if (subItem != null && !String.IsNullOrEmpty(subItem.Url) && subItem.Url != subItem.Text && this.HotCellHitLocation == HitTestLocation.Text) @@ -8605,11 +9405,13 @@ namespace BrightIdeasSoftware /// The modelObject whose item is to be found /// The OLVListItem that displays the model, or null /// This method has O(n) performance. - public virtual OLVListItem ModelToItem(object modelObject) { + public virtual OLVListItem ModelToItem(object modelObject) + { if (modelObject == null) return null; - foreach (OLVListItem olvi in this.Items) { + foreach (OLVListItem olvi in this.Items) + { if (olvi.RowObject != null && olvi.RowObject.Equals(modelObject)) return olvi; } @@ -8619,24 +9421,31 @@ namespace BrightIdeasSoftware /// /// Do the work required after the items in a listview have been created /// - protected virtual void PostProcessRows() { + protected virtual void PostProcessRows() + { // If this method is called during a BeginUpdate/EndUpdate pair, changes to the // Items collection are cached. Getting the Count flushes that cache. #pragma warning disable 168 -// ReSharper disable once UnusedVariable + // ReSharper disable once UnusedVariable int count = this.Items.Count; #pragma warning restore 168 int i = 0; - if (this.ShowGroups) { - foreach (ListViewGroup group in this.Groups) { - foreach (OLVListItem olvi in group.Items) { + if (this.ShowGroups) + { + foreach (ListViewGroup group in this.Groups) + { + foreach (OLVListItem olvi in group.Items) + { this.PostProcessOneRow(olvi.Index, i, olvi); i++; } } - } else { - foreach (OLVListItem olvi in this.Items) { + } + else + { + foreach (OLVListItem olvi in this.Items) + { this.PostProcessOneRow(olvi.Index, i, olvi); i++; } @@ -8646,12 +9455,14 @@ namespace BrightIdeasSoftware /// /// Do the work required after one item in a listview have been created /// - protected virtual void PostProcessOneRow(int rowIndex, int displayIndex, OLVListItem olvi) { - if (this.UseAlternatingBackColors && this.View == View.Details && olvi.Enabled) { + protected virtual void PostProcessOneRow(int rowIndex, int displayIndex, OLVListItem olvi) + { + if (this.UseAlternatingBackColors && this.View == View.Details && olvi.Enabled) + { olvi.UseItemStyleForSubItems = true; olvi.BackColor = displayIndex % 2 == 1 ? this.AlternateRowBackColorOrDefault : this.BackColor; } - if (this.ShowImagesOnSubItems && !this.VirtualMode) + if (this.ShowImagesOnSubItems && !this.VirtualMode) this.SetSubItemImages(rowIndex, olvi); bool needToTriggerFormatCellEvents = this.TriggerFormatRowEvent(rowIndex, displayIndex, olvi); @@ -8662,14 +9473,16 @@ namespace BrightIdeasSoftware // If we're going to have per cell formatting, we need to copy the formatting // of the item into each cell, before triggering the cell format events - if (needToTriggerFormatCellEvents) { + if (needToTriggerFormatCellEvents) + { PropagateFormatFromRowToCells(olvi); this.TriggerFormatCellEvents(rowIndex, displayIndex, olvi); } // Similarly, if any cell in the row has hyperlinks, we have to copy formatting // from the item into each cell before applying the hyperlink style - if (this.UseHyperlinks && olvi.HasAnyHyperlinks) { + if (this.UseHyperlinks && olvi.HasAnyHyperlinks) + { PropagateFormatFromRowToCells(olvi); this.ApplyHyperlinkStyle(olvi); } @@ -8684,14 +9497,16 @@ namespace BrightIdeasSoftware /// useable because it still refers to the position in the overall list, not the display order. /// [Obsolete("This method is no longer used. Override PostProcessOneRow() to achieve a similar result")] - protected virtual void PrepareAlternateBackColors() { + protected virtual void PrepareAlternateBackColors() + { } /// /// Setup all subitem images on all rows /// [Obsolete("This method is not longer maintained and will be removed", false)] - protected virtual void SetAllSubItemImages() { + protected virtual void SetAllSubItemImages() + { //if (!this.ShowImagesOnSubItems || this.OwnerDraw) // return; @@ -8706,7 +9521,8 @@ namespace BrightIdeasSoftware /// /// the index at which the item occurs /// the item whose subitems are to be set - protected virtual void SetSubItemImages(int rowIndex, OLVListItem item) { + protected virtual void SetSubItemImages(int rowIndex, OLVListItem item) + { this.SetSubItemImages(rowIndex, item, false); } @@ -8716,11 +9532,13 @@ namespace BrightIdeasSoftware /// the index at which the item occurs /// the item whose subitems are to be set /// will existing images be cleared if no new image is provided? - protected virtual void SetSubItemImages(int rowIndex, OLVListItem item, bool shouldClearImages) { + protected virtual void SetSubItemImages(int rowIndex, OLVListItem item, bool shouldClearImages) + { if (!this.ShowImagesOnSubItems || this.OwnerDraw) return; - for (int i = 1; i < item.SubItems.Count; i++) { + for (int i = 1; i < item.SubItems.Count; i++) + { this.SetSubItemImage(rowIndex, i, item.GetSubItem(i), shouldClearImages); } } @@ -8732,7 +9550,8 @@ namespace BrightIdeasSoftware /// /// /// - public virtual void SetSubItemImage(int rowIndex, int subItemIndex, OLVListSubItem subItem, bool shouldClearImages) { + public virtual void SetSubItemImage(int rowIndex, int subItemIndex, OLVListSubItem subItem, bool shouldClearImages) + { int imageIndex = this.GetActualImageIndex(subItem.ImageSelector); if (shouldClearImages || imageIndex != -1) NativeMethods.SetSubItemImage(this, rowIndex, subItemIndex, imageIndex); @@ -8751,7 +9570,8 @@ namespace BrightIdeasSoftware /// This method has the intentional side-effect of converting our list of objects to an ArrayList. /// /// - protected virtual void TakeOwnershipOfObjects() { + protected virtual void TakeOwnershipOfObjects() + { if (this.isOwnerOfObjects) return; @@ -8766,7 +9586,8 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual bool TriggerFormatRowEvent(int rowIndex, int displayIndex, OLVListItem olvi) { + protected virtual bool TriggerFormatRowEvent(int rowIndex, int displayIndex, OLVListItem olvi) + { FormatRowEventArgs args = new FormatRowEventArgs(); args.ListView = this; args.RowIndex = rowIndex; @@ -8783,7 +9604,8 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void TriggerFormatCellEvents(int rowIndex, int displayIndex, OLVListItem olvi) { + protected virtual void TriggerFormatCellEvents(int rowIndex, int displayIndex, OLVListItem olvi) + { PropagateFormatFromRowToCells(olvi); @@ -8793,7 +9615,8 @@ namespace BrightIdeasSoftware args2.RowIndex = rowIndex; args2.DisplayIndex = displayIndex; args2.Item = olvi; - for (int i = 0; i < this.Columns.Count; i++) { + for (int i = 0; i < this.Columns.Count; i++) + { args2.ColumnIndex = i; args2.Column = this.GetColumn(i); args2.SubItem = olvi.GetSubItem(i); @@ -8801,7 +9624,8 @@ namespace BrightIdeasSoftware } } - private static void PropagateFormatFromRowToCells(OLVListItem olvi) { + private static void PropagateFormatFromRowToCells(OLVListItem olvi) + { // If a cell isn't given its own colors, it *should* use the colors of the item. // However, there is a bug in the .NET framework where the cell are given // the colors of the ListView instead of the colors of the row. @@ -8815,7 +9639,8 @@ namespace BrightIdeasSoftware Color backColor = olvi.BackColor; Color foreColor = olvi.ForeColor; Font font = olvi.Font; - foreach (OLVListSubItem subitem in olvi.SubItems) { + foreach (OLVListSubItem subitem in olvi.SubItems) + { subitem.BackColor = backColor; subitem.ForeColor = foreColor; subitem.Font = font; @@ -8826,7 +9651,8 @@ namespace BrightIdeasSoftware /// Make the list forget everything -- all rows and all columns /// /// Use if you want to remove just the rows. - public virtual void Reset() { + public virtual void Reset() + { this.Clear(); this.AllColumns.Clear(); this.ClearObjects(); @@ -8843,18 +9669,21 @@ namespace BrightIdeasSoftware #region ISupportInitialize Members - void ISupportInitialize.BeginInit() { + void ISupportInitialize.BeginInit() + { this.Frozen = true; } - void ISupportInitialize.EndInit() { - if (this.RowHeight != -1) { - this.SmallImageList = this.SmallImageList; - if (this.CheckBoxes) + void ISupportInitialize.EndInit() + { + if (this.RowHeight != -1) + { + this.SetSmallImageList(this.GetSmallImageList()); + if (this.GetCheckBoxes()) this.InitializeStateImageList(); } - if (this.UseSubItemCheckBoxes || (this.VirtualMode && this.CheckBoxes)) + if (this.UseSubItemCheckBoxes || (this.VirtualMode && this.GetCheckBoxes())) this.SetupSubItemCheckBoxes(); this.Frozen = false; @@ -8867,13 +9696,15 @@ namespace BrightIdeasSoftware /// /// Update our externally visible image list so it holds the same images as our shadow list, but sized correctly /// - private void SetupBaseImageList() { + private void SetupBaseImageList() + { // If a row height hasn't been set, or an image list has been give which is the required size, just assign it if (rowHeight == -1 || this.View != View.Details || (this.shadowedImageList != null && this.shadowedImageList.ImageSize.Height == rowHeight)) this.BaseSmallImageList = this.shadowedImageList; - else { + else + { int width = (this.shadowedImageList == null ? 16 : this.shadowedImageList.ImageSize.Width); this.BaseSmallImageList = this.MakeResizedImageList(width, rowHeight, shadowedImageList); } @@ -8887,7 +9718,8 @@ namespace BrightIdeasSoftware /// Height and width of the new images /// Source of the images (can be null) /// A new image list - private ImageList MakeResizedImageList(int width, int height, ImageList source) { + private ImageList MakeResizedImageList(int width, int height, ImageList source) + { ImageList il = new ImageList(); il.ImageSize = new Size(width, height); @@ -8899,13 +9731,15 @@ namespace BrightIdeasSoftware il.ColorDepth = source.ColorDepth; // Fill the imagelist with resized copies from the source - for (int i = 0; i < source.Images.Count; i++) { + for (int i = 0; i < source.Images.Count; i++) + { Bitmap bm = this.MakeResizedImage(width, height, source.Images[i], source.TransparentColor); il.Images.Add(bm); } // Give each image the same key it has in the original - foreach (String key in source.Images.Keys) { + foreach (String key in source.Images.Keys) + { il.Images.SetKeyName(source.Images.IndexOfKey(key), key); } @@ -8920,7 +9754,8 @@ namespace BrightIdeasSoftware /// Image to be centred /// The background color /// A new bitmap - private Bitmap MakeResizedImage(int width, int height, Image image, Color transparent) { + private Bitmap MakeResizedImage(int width, int height, Image image, Color transparent) + { Bitmap bm = new Bitmap(width, height); Graphics g = Graphics.FromImage(bm); g.Clear(transparent); @@ -8933,14 +9768,16 @@ namespace BrightIdeasSoftware /// /// Initialize the state image list with the required checkbox images /// - protected virtual void InitializeStateImageList() { + protected virtual void InitializeStateImageList() + { if (this.DesignMode) return; - if (!this.CheckBoxes) + if (!this.GetCheckBoxes()) return; - if (this.StateImageList == null) { + if (this.StateImageList == null) + { this.StateImageList = new ImageList(); this.StateImageList.ImageSize = new Size(16, this.RowHeight == -1 ? 16 : this.RowHeight); this.StateImageList.ColorDepth = ColorDepth.Depth32Bit; @@ -8948,7 +9785,8 @@ namespace BrightIdeasSoftware if (this.RowHeight != -1 && this.View == View.Details && - this.StateImageList.ImageSize.Height != this.RowHeight) { + this.StateImageList.ImageSize.Height != this.RowHeight) + { this.StateImageList = new ImageList(); this.StateImageList.ImageSize = new Size(16, this.RowHeight); this.StateImageList.ColorDepth = ColorDepth.Depth32Bit; @@ -8963,7 +9801,8 @@ namespace BrightIdeasSoftware this.AddCheckStateBitmap(this.StateImageList, CHECKED_KEY, CheckBoxState.CheckedNormal); if (this.TriStateCheckBoxes && this.StateImageList.Images.Count <= 2) this.AddCheckStateBitmap(this.StateImageList, INDETERMINATE_KEY, CheckBoxState.MixedNormal); - else { + else + { if (this.StateImageList.Images.ContainsKey(INDETERMINATE_KEY)) this.StateImageList.Images.RemoveByKey(INDETERMINATE_KEY); } @@ -8989,9 +9828,10 @@ namespace BrightIdeasSoftware /// (or primary checkboxes in virtual mode) /// /// This gives the ListView a small image list, if it doesn't already have one. - public virtual void SetupSubItemCheckBoxes() { + public virtual void SetupSubItemCheckBoxes() + { this.ShowImagesOnSubItems = true; - if (this.SmallImageList == null || !this.SmallImageList.Images.ContainsKey(CHECKED_KEY)) + if (this.GetSmallImageList() == null || !this.GetSmallImageList().Images.ContainsKey(CHECKED_KEY)) this.InitializeSubItemCheckBoxImages(); } @@ -9011,13 +9851,15 @@ namespace BrightIdeasSoftware /// by images in the StateImageList, but per-cell checkboxes are handled by images in the SmallImageList. /// /// - protected virtual void InitializeSubItemCheckBoxImages() { + protected virtual void InitializeSubItemCheckBoxImages() + { // Don't mess with the image list in design mode if (this.DesignMode) return; - ImageList il = this.SmallImageList; - if (il == null) { + ImageList il = this.GetSmallImageList(); + if (il == null) + { il = new ImageList(); il.ImageSize = new Size(16, 16); il.ColorDepth = ColorDepth.Depth32Bit; @@ -9027,10 +9869,11 @@ namespace BrightIdeasSoftware this.AddCheckStateBitmap(il, UNCHECKED_KEY, CheckBoxState.UncheckedNormal); this.AddCheckStateBitmap(il, INDETERMINATE_KEY, CheckBoxState.MixedNormal); - this.SmallImageList = il; + this.SetSmallImageList(il); } - private void AddCheckStateBitmap(ImageList il, string key, CheckBoxState boxState) { + private void AddCheckStateBitmap(ImageList il, string key, CheckBoxState boxState) + { Bitmap b = new Bitmap(il.ImageSize.Width, il.ImageSize.Height); Graphics g = Graphics.FromImage(b); g.Clear(il.TransparentColor); @@ -9047,7 +9890,8 @@ namespace BrightIdeasSoftware /// Owner draw the column header /// /// - protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e) { + protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e) + { e.DrawDefault = true; base.OnDrawColumnHeader(e); } @@ -9056,13 +9900,16 @@ namespace BrightIdeasSoftware /// Owner draw the item /// /// - protected override void OnDrawItem(DrawListViewItemEventArgs e) { + protected override void OnDrawItem(DrawListViewItemEventArgs e) + { if (this.View == View.Details) e.DrawDefault = false; - else { + else + { if (this.ItemRenderer == null) e.DrawDefault = true; - else { + else + { Object row = ((OLVListItem)e.Item).RowObject; e.DrawDefault = !this.ItemRenderer.RenderItem(e, e.Graphics, e.Bounds, row); } @@ -9076,10 +9923,12 @@ namespace BrightIdeasSoftware /// Owner draw a single subitem /// /// - protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e) { + protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e) + { //System.Diagnostics.Debug.WriteLine(String.Format("OnDrawSubItem ({0}, {1})", e.ItemIndex, e.ColumnIndex)); // Don't try to do owner drawing at design time - if (this.DesignMode) { + if (this.DesignMode) + { e.DrawDefault = true; return; } @@ -9123,7 +9972,8 @@ namespace BrightIdeasSoftware /// So we have to remember the click count from the preceding mouse down event. /// /// - protected override void OnMouseDown(MouseEventArgs e) { + protected override void OnMouseDown(MouseEventArgs e) + { this.lastMouseDownClickCount = e.Clicks; base.OnMouseDown(e); } @@ -9133,13 +9983,14 @@ namespace BrightIdeasSoftware /// When the mouse leaves the control, remove any hot item highlighting /// /// - protected override void OnMouseLeave(EventArgs e) { + protected override void OnMouseLeave(EventArgs e) + { base.OnMouseLeave(e); if (!this.Created) return; - this.UpdateHotItem(new Point(-1,-1)); + this.UpdateHotItem(new Point(-1, -1)); } // We could change the hot item on the mouse hover event, but it looks wrong. @@ -9154,14 +10005,16 @@ namespace BrightIdeasSoftware /// When the mouse moves, we might need to change the hot item. /// /// - protected override void OnMouseMove(MouseEventArgs e) { + protected override void OnMouseMove(MouseEventArgs e) + { base.OnMouseMove(e); if (this.Created) HandleMouseMove(e.Location); } - internal void HandleMouseMove(Point pt) { + internal void HandleMouseMove(Point pt) + { //System.Diagnostics.Debug.WriteLine(String.Format("HandleMouseMove: {0}", pt)); @@ -9178,7 +10031,8 @@ namespace BrightIdeasSoftware /// Check to see if we need to start editing a cell /// /// - protected override void OnMouseUp(MouseEventArgs e) { + protected override void OnMouseUp(MouseEventArgs e) + { //System.Diagnostics.Debug.WriteLine(String.Format("OnMouseUp")); @@ -9187,7 +10041,8 @@ namespace BrightIdeasSoftware if (!this.Created) return; - if (e.Button == MouseButtons.Right) { + if (e.Button == MouseButtons.Right) + { this.OnRightMouseUp(e); return; } @@ -9215,7 +10070,8 @@ namespace BrightIdeasSoftware if (this.UseHyperlinks && args.HitTest.HitTestLocation == HitTestLocation.Text && args.SubItem != null && - !String.IsNullOrEmpty(args.SubItem.Url)) { + !String.IsNullOrEmpty(args.SubItem.Url)) + { // We have to delay the running of this process otherwise we can generate // a series of MouseUp events (don't ask me why) this.BeginInvoke((MethodInvoker)delegate { this.ProcessHyperlinkClicked(args); }); @@ -9226,11 +10082,11 @@ namespace BrightIdeasSoftware return; // We only start the edit if the user clicked on the image or text. - if (args.HitTest.HitTestLocation == HitTestLocation.Nothing) + if (args.HitTest.HitTestLocation == HitTestLocation.Nothing) return; // We don't edit the primary column by single clicks -- only subitems. - if (this.CellEditActivation == CellEditActivateMode.SingleClick && args.ColumnIndex <= 0) + if (this.CellEditActivation == CellEditActivateMode.SingleClick && args.ColumnIndex <= 0) return; // Don't start a cell edit operation when the user clicks on the background of a checkbox column -- it just looks wrong. @@ -9246,7 +10102,8 @@ namespace BrightIdeasSoftware /// do the default processing. /// /// - protected virtual void ProcessHyperlinkClicked(CellClickEventArgs e) { + protected virtual void ProcessHyperlinkClicked(CellClickEventArgs e) + { HyperlinkClickedEventArgs args = new HyperlinkClickedEventArgs(); args.HitTest = e.HitTest; args.ListView = this; @@ -9260,7 +10117,8 @@ namespace BrightIdeasSoftware args.ModifierKeys = Control.ModifierKeys; args.Url = e.SubItem.Url; this.OnHyperlinkClicked(args); - if (!args.Handled) { + if (!args.Handled) + { this.StandardHyperlinkClickedProcessing(args); } } @@ -9270,15 +10128,21 @@ namespace BrightIdeasSoftware /// is to try and open the url. /// /// - protected virtual void StandardHyperlinkClickedProcessing(HyperlinkClickedEventArgs args) { + protected virtual void StandardHyperlinkClickedProcessing(HyperlinkClickedEventArgs args) + { Cursor originalCursor = this.Cursor; - try { + try + { this.Cursor = Cursors.WaitCursor; System.Diagnostics.Process.Start(args.Url); - } catch (Win32Exception) { + } + catch (Win32Exception) + { System.Media.SystemSounds.Beep.Play(); // ignore it - } finally { + } + finally + { this.Cursor = originalCursor; } this.MarkUrlVisited(args.Url); @@ -9289,22 +10153,27 @@ namespace BrightIdeasSoftware /// The user right clicked on the control /// /// - protected virtual void OnRightMouseUp(MouseEventArgs e) { + protected virtual void OnRightMouseUp(MouseEventArgs e) + { CellRightClickEventArgs args = new CellRightClickEventArgs(); this.BuildCellEvent(args, e.Location); this.OnCellRightClick(args); - if (!args.Handled) { - if (args.MenuStrip != null) { + if (!args.Handled) + { + if (args.MenuStrip != null) + { args.MenuStrip.Show(this, args.Location); } } } - internal void BuildCellEvent(CellEventArgs args, Point location) { + internal void BuildCellEvent(CellEventArgs args, Point location) + { BuildCellEvent(args, location, this.OlvHitTest(location.X, location.Y)); } - internal void BuildCellEvent(CellEventArgs args, Point location, OlvListViewHitTestInfo hitTest) { + internal void BuildCellEvent(CellEventArgs args, Point location, OlvListViewHitTestInfo hitTest) + { args.HitTest = hitTest; args.ListView = this; args.Location = location; @@ -9319,7 +10188,8 @@ namespace BrightIdeasSoftware // In non-details view, we want any hit on an item to act as if it was a hit // on column 0 -- which, effectively, it was. - if (args.Item != null && args.ListView.View != View.Details) { + if (args.Item != null && args.ListView.View != View.Details) + { args.ColumnIndex = 0; args.Column = args.ListView.GetColumn(0); args.SubItem = args.Item.GetSubItem(0); @@ -9332,7 +10202,8 @@ namespace BrightIdeasSoftware /// trigger one event for any number of select/deselects that come from one user action /// /// - protected override void OnSelectedIndexChanged(EventArgs e) { + protected override void OnSelectedIndexChanged(EventArgs e) + { if (this.SelectionEventsSuspended) return; @@ -9341,7 +10212,8 @@ namespace BrightIdeasSoftware // If we haven't already scheduled an event, schedule it to be triggered // By using idle time, we will wait until all select events for the same // user action have finished before triggering the event. - if (!this.hasIdleHandler) { + if (!this.hasIdleHandler) + { this.hasIdleHandler = true; this.RunWhenIdle(HandleApplicationIdle); } @@ -9351,7 +10223,8 @@ namespace BrightIdeasSoftware /// Called when the handle of the underlying control is created /// /// - protected override void OnHandleCreated(EventArgs e) { + protected override void OnHandleCreated(EventArgs e) + { //Debug.WriteLine("OnHandleCreated"); base.OnHandleCreated(e); @@ -9361,7 +10234,8 @@ namespace BrightIdeasSoftware /// /// This method is called after the control has been fully created. /// - protected virtual void OnControlCreated() { + protected virtual void OnControlCreated() + { //Debug.WriteLine("OnControlCreated"); @@ -9393,7 +10267,8 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual bool ShouldStartCellEdit(MouseEventArgs e) { + protected virtual bool ShouldStartCellEdit(MouseEventArgs e) + { if (this.IsCellEditing) return false; @@ -9417,32 +10292,36 @@ namespace BrightIdeasSoftware /// /// /// - protected override bool ProcessDialogKey(Keys keyData) { + protected override bool ProcessDialogKey(Keys keyData) + { - if (this.IsCellEditing) + if (this.IsCellEditing) return this.CellEditKeyEngine.HandleKey(this, keyData); // Treat F2 as a request to edit the primary column - if (keyData == Keys.F2) { + if (keyData == Keys.F2) + { this.EditSubItem((OLVListItem)this.FocusedItem, 0); return base.ProcessDialogKey(keyData); } // Treat Ctrl-C as Copy To Clipboard. - if (this.CopySelectionOnControlC && keyData == (Keys.C | Keys.Control)) { + if (this.CopySelectionOnControlC && keyData == (Keys.C | Keys.Control)) + { this.CopySelectionToClipboard(); return true; } // Treat Ctrl-A as Select All. - if (this.SelectAllOnControlA && keyData == (Keys.A | Keys.Control)) { + if (this.SelectAllOnControlA && keyData == (Keys.A | Keys.Control)) + { this.SelectAll(); return true; } return base.ProcessDialogKey(keyData); } - + /// /// Start an editing operation on the first editable column of the given model. /// @@ -9455,13 +10334,16 @@ namespace BrightIdeasSoftware /// This will start an edit operation regardless of CellActivationMode. /// /// - public virtual void EditModel(object rowModel) { + public virtual void EditModel(object rowModel) + { OLVListItem olvItem = this.ModelToItem(rowModel); if (olvItem == null) return; - for (int i = 0; i < olvItem.SubItems.Count; i++) { - if (this.GetColumn(i).IsEditable) { + for (int i = 0; i < olvItem.SubItems.Count; i++) + { + if (this.GetColumn(i).IsEditable) + { this.StartCellEdit(olvItem, i); return; } @@ -9474,7 +10356,8 @@ namespace BrightIdeasSoftware /// This performs various sanity checks and passes off the real work to StartCellEdit(). /// The row to be edited /// The index of the cell to be edited - public virtual void EditSubItem(OLVListItem item, int subItemIndex) { + public virtual void EditSubItem(OLVListItem item, int subItemIndex) + { if (item == null) return; @@ -9498,7 +10381,8 @@ namespace BrightIdeasSoftware /// /// The row to be edited /// The index of the cell to be edited - public virtual void StartCellEdit(OLVListItem item, int subItemIndex) { + public virtual void StartCellEdit(OLVListItem item, int subItemIndex) + { OLVColumn column = this.GetColumn(subItemIndex); Control c = this.GetCellEditor(item, subItemIndex); Rectangle cellBounds = this.CalculateCellBounds(item, subItemIndex); @@ -9518,7 +10402,7 @@ namespace BrightIdeasSoftware // The event handler may have completely changed the control, so we need to remember it this.cellEditor = this.CellEditEventArgs.Control; - + this.Invalidate(); this.Controls.Add(this.cellEditor); this.ConfigureControl(); @@ -9534,12 +10418,13 @@ namespace BrightIdeasSoftware /// /// /// - public Rectangle CalculateCellEditorBounds(OLVListItem item, int subItemIndex, Size preferredSize) { + public Rectangle CalculateCellEditorBounds(OLVListItem item, int subItemIndex, Size preferredSize) + { Rectangle r = CalculateCellBounds(item, subItemIndex); // Calculate the width of the cell's current contents - return this.OwnerDraw - ? CalculateCellEditorBoundsOwnerDrawn(item, subItemIndex, r, preferredSize) + return this.OwnerDraw + ? CalculateCellEditorBoundsOwnerDrawn(item, subItemIndex, r, preferredSize) : CalculateCellEditorBoundsStandard(item, subItemIndex, r, preferredSize); } @@ -9552,7 +10437,8 @@ namespace BrightIdeasSoftware /// /// /// A rectangle that is the bounds of the cell editor - protected Rectangle CalculateCellEditorBoundsOwnerDrawn(OLVListItem item, int subItemIndex, Rectangle r, Size preferredSize) { + protected Rectangle CalculateCellEditorBoundsOwnerDrawn(OLVListItem item, int subItemIndex, Rectangle r, Size preferredSize) + { IRenderer renderer = this.View == View.Details ? this.GetCellRenderer(item.RowObject, this.GetColumn(subItemIndex)) : this.ItemRenderer; @@ -9560,7 +10446,8 @@ namespace BrightIdeasSoftware if (renderer == null) return r; - using (Graphics g = this.CreateGraphics()) { + using (Graphics g = this.CreateGraphics()) + { return renderer.GetEditRectangle(g, r, item, subItemIndex, preferredSize); } } @@ -9574,7 +10461,8 @@ namespace BrightIdeasSoftware /// /// /// A rectangle that is the bounds of the cell editor - protected Rectangle CalculateCellEditorBoundsStandard(OLVListItem item, int subItemIndex, Rectangle cellBounds, Size preferredSize) { + protected Rectangle CalculateCellEditorBoundsStandard(OLVListItem item, int subItemIndex, Rectangle cellBounds, Size preferredSize) + { if (this.View == View.Tile) return cellBounds; @@ -9583,7 +10471,7 @@ namespace BrightIdeasSoftware cellBounds.Y += (cellBounds.Height - preferredSize.Height) / 2; // Only Details view needs more processing - if (this.View != View.Details) + if (this.View != View.Details) return cellBounds; // Allow for image (if there is one). @@ -9591,27 +10479,32 @@ namespace BrightIdeasSoftware object imageSelector = null; if (subItemIndex == 0) imageSelector = item.ImageSelector; - else { + else + { // We only check for subitem images if we are owner drawn or showing subitem images if (this.OwnerDraw || this.ShowImagesOnSubItems) imageSelector = item.GetSubItem(subItemIndex).ImageSelector; } - if (this.GetActualImageIndex(imageSelector) != -1) { + if (this.GetActualImageIndex(imageSelector) != -1) + { offset += this.SmallImageSize.Width + 2; } // Allow for checkbox - if (this.CheckBoxes && this.StateImageList != null && subItemIndex == 0) { + if (this.GetCheckBoxes() && this.StateImageList != null && subItemIndex == 0) + { offset += this.StateImageList.ImageSize.Width + 2; } // Allow for indent (first column only) - if (subItemIndex == 0 && item.IndentCount > 0) { + if (subItemIndex == 0 && item.IndentCount > 0) + { offset += (this.SmallImageSize.Width * item.IndentCount); } // Do the adjustment - if (offset > 0) { + if (offset > 0) + { cellBounds.X += offset; cellBounds.Width -= offset; } @@ -9626,14 +10519,17 @@ namespace BrightIdeasSoftware /// A control /// The value to be given to the control /// The string to be given if the value doesn't work - protected virtual void SetControlValue(Control control, Object value, String stringValue) { + protected virtual void SetControlValue(Control control, Object value, String stringValue) + { // Handle combobox explicitly ComboBox cb = control as ComboBox; - if (cb != null) { + if (cb != null) + { if (cb.Created) cb.SelectedValue = value; else - this.BeginInvoke(new MethodInvoker(delegate { + this.BeginInvoke(new MethodInvoker(delegate + { cb.SelectedValue = value; })); return; @@ -9648,7 +10544,8 @@ namespace BrightIdeasSoftware String valueAsString = value as String; control.Text = valueAsString ?? stringValue; } - catch (ArgumentOutOfRangeException) { + catch (ArgumentOutOfRangeException) + { // The value couldn't be set via the Text property. } } @@ -9656,7 +10553,8 @@ namespace BrightIdeasSoftware /// /// Setup the given control to be a cell editor /// - protected virtual void ConfigureControl() { + protected virtual void ConfigureControl() + { this.cellEditor.Validating += new CancelEventHandler(CellEditor_Validating); this.cellEditor.Select(); } @@ -9666,7 +10564,8 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual Object GetControlValue(Control control) { + protected virtual Object GetControlValue(Control control) + { if (control == null) return null; @@ -9682,11 +10581,16 @@ namespace BrightIdeasSoftware if (checkBox != null) return checkBox.Checked; - try { + try + { return control.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, control, null); - } catch (MissingMethodException) { // Microsoft throws this + } + catch (MissingMethodException) + { // Microsoft throws this return control.Text; - } catch (MissingFieldException) { // Mono throws this + } + catch (MissingFieldException) + { // Mono throws this return control.Text; } } @@ -9696,15 +10600,18 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void CellEditor_Validating(object sender, CancelEventArgs e) { + protected virtual void CellEditor_Validating(object sender, CancelEventArgs e) + { this.CellEditEventArgs.Cancel = false; this.CellEditEventArgs.NewValue = this.GetControlValue(this.cellEditor); this.OnCellEditorValidating(this.CellEditEventArgs); - if (this.CellEditEventArgs.Cancel) { + if (this.CellEditEventArgs.Cancel) + { this.CellEditEventArgs.Control.Select(); e.Cancel = true; - } else + } + else FinishCellEdit(); } @@ -9714,7 +10621,8 @@ namespace BrightIdeasSoftware /// The row to be edited /// The index of the cell to be edited /// A Rectangle - public virtual Rectangle CalculateCellBounds(OLVListItem item, int subItemIndex) { + public virtual Rectangle CalculateCellBounds(OLVListItem item, int subItemIndex) + { // It seems on Win7, GetSubItemBounds() does not have the same problems with // column 0 that it did previously. @@ -9723,7 +10631,7 @@ namespace BrightIdeasSoftware if (this.View != View.Details) return this.GetItemRect(item.Index, ItemBoundsPortion.Label); - + Rectangle r = item.GetSubItemBounds(subItemIndex); r.Width -= 1; r.Height -= 1; @@ -9741,18 +10649,21 @@ namespace BrightIdeasSoftware /// The row to be edited /// The index of the cell to be edited /// A Rectangle - public virtual Rectangle CalculateCellTextBounds(OLVListItem item, int subItemIndex) { + public virtual Rectangle CalculateCellTextBounds(OLVListItem item, int subItemIndex) + { return this.CalculateCellBounds(item, subItemIndex, ItemBoundsPortion.ItemOnly); } - private Rectangle CalculateCellBounds(OLVListItem item, int subItemIndex, ItemBoundsPortion portion) { + private Rectangle CalculateCellBounds(OLVListItem item, int subItemIndex, ItemBoundsPortion portion) + { // SubItem.Bounds works for every subitem, except the first. if (subItemIndex > 0) return item.GetSubItemBounds(subItemIndex); // For non detail views, we just use the requested portion Rectangle r = this.GetItemRect(item.Index, portion); - if (r.Y < -10000000 || r.Y > 10000000) { + if (r.Y < -10000000 || r.Y > 10000000) + { r.Y = item.Bounds.Y; } if (this.View != View.Details) @@ -9813,7 +10724,8 @@ namespace BrightIdeasSoftware /// The row to be edited /// The index of the cell to be edited /// A Control to edit the given cell - protected virtual Control GetCellEditor(OLVListItem item, int subItemIndex) { + protected virtual Control GetCellEditor(OLVListItem item, int subItemIndex) + { OLVColumn column = this.GetColumn(subItemIndex); Object value = column.GetValue(item.RowObject) ?? this.GetFirstNonNullValue(column); @@ -9833,8 +10745,10 @@ namespace BrightIdeasSoftware /// /// /// The first non-null value, or null if no non-null values were found - internal object GetFirstNonNullValue(OLVColumn column) { - for (int i = 0; i < Math.Min(this.GetItemCount(), 1000); i++) { + internal object GetFirstNonNullValue(OLVColumn column) + { + for (int i = 0; i < Math.Min(this.GetItemCount(), 1000); i++) + { object value = column.GetValue(this.GetModelObject(i)); if (value != null) return value; @@ -9847,7 +10761,8 @@ namespace BrightIdeasSoftware /// /// What column does the cell belong to? /// - protected virtual Control MakeDefaultCellEditor(OLVColumn column) { + protected virtual Control MakeDefaultCellEditor(OLVColumn column) + { TextBox tb = new TextBox(); if (column.AutoCompleteEditor) this.ConfigureAutoComplete(tb, column); @@ -9860,7 +10775,8 @@ namespace BrightIdeasSoftware /// /// The textbox to configure /// The column used to calculate values - public void ConfigureAutoComplete(TextBox tb, OLVColumn column) { + public void ConfigureAutoComplete(TextBox tb, OLVColumn column) + { this.ConfigureAutoComplete(tb, column, 1000); } @@ -9872,7 +10788,8 @@ namespace BrightIdeasSoftware /// The textbox to configure /// The column used to calculate values /// Consider only this many rows - public void ConfigureAutoComplete(TextBox tb, OLVColumn column, int maxRows) { + public void ConfigureAutoComplete(TextBox tb, OLVColumn column, int maxRows) + { // Don't consider more rows than we actually have maxRows = Math.Min(this.GetItemCount(), maxRows); @@ -9884,9 +10801,11 @@ namespace BrightIdeasSoftware // Build a list of unique values, to be used as autocomplete on the editor Dictionary alreadySeen = new Dictionary(); List values = new List(); - for (int i = 0; i < maxRows; i++) { + for (int i = 0; i < maxRows; i++) + { string valueAsString = column.GetStringValue(this.GetModelObject(i)); - if (!String.IsNullOrEmpty(valueAsString) && !alreadySeen.ContainsKey(valueAsString)) { + if (!String.IsNullOrEmpty(valueAsString) && !alreadySeen.ContainsKey(valueAsString)) + { values.Add(valueAsString); alreadySeen[valueAsString] = true; } @@ -9900,7 +10819,8 @@ namespace BrightIdeasSoftware /// /// Stop editing a cell and throw away any changes. /// - public virtual void CancelCellEdit() { + public virtual void CancelCellEdit() + { if (!this.IsCellEditing) return; @@ -9922,7 +10842,8 @@ namespace BrightIdeasSoftware /// process can cause the finishing to be aborted. Developers should check the return value /// or use IsCellEditing property after calling this method to see if the user is still /// editing a cell. - public virtual bool PossibleFinishCellEditing() { + public virtual bool PossibleFinishCellEditing() + { return this.PossibleFinishCellEditing(false); } @@ -9937,7 +10858,8 @@ namespace BrightIdeasSoftware /// editing a cell. /// True if it is likely that another cell is going to be /// edited immediately after this cell finishes editing - public virtual bool PossibleFinishCellEditing(bool expectingCellEdit) { + public virtual bool PossibleFinishCellEditing(bool expectingCellEdit) + { if (!this.IsCellEditing) return true; @@ -9958,7 +10880,8 @@ namespace BrightIdeasSoftware /// /// This method does not trigger a Validating event, so it always finishes /// the cell edit. - public virtual void FinishCellEdit() { + public virtual void FinishCellEdit() + { this.FinishCellEdit(false); } @@ -9969,7 +10892,8 @@ namespace BrightIdeasSoftware /// the cell edit. /// True if it is likely that another cell is going to be /// edited immediately after this cell finishes editing - public virtual void FinishCellEdit(bool expectingCellEdit) { + public virtual void FinishCellEdit(bool expectingCellEdit) + { if (!this.IsCellEditing) return; @@ -9978,7 +10902,8 @@ namespace BrightIdeasSoftware this.OnCellEditFinishing(this.CellEditEventArgs); // If someone doesn't cancel the editing process, write the value back into the model - if (!this.CellEditEventArgs.Cancel) { + if (!this.CellEditEventArgs.Cancel) + { this.CellEditEventArgs.Column.PutValue(this.CellEditEventArgs.RowObject, this.CellEditEventArgs.NewValue); this.RefreshItem(this.CellEditEventArgs.ListViewItem); } @@ -9995,7 +10920,8 @@ namespace BrightIdeasSoftware /// True if it is likely that another cell is going to be /// edited immediately after this cell finishes editing /// True if the cell editor should be disposed - protected virtual void CleanupCellEdit(bool expectingCellEdit, bool disposeOfCellEditor) { + protected virtual void CleanupCellEdit(bool expectingCellEdit, bool disposeOfCellEditor) + { if (this.cellEditor == null) return; @@ -10010,14 +10936,16 @@ namespace BrightIdeasSoftware // momentarily (after the cell editor is remove and before the new one is created) // causing the list's selection to flash momentarily. EventHandler toBeRun = null; - toBeRun = delegate(object sender, EventArgs e) { + toBeRun = delegate (object sender, EventArgs e) + { Application.Idle -= toBeRun; this.Controls.Remove(soonToBeOldCellEditor); if (disposeOfCellEditor) soonToBeOldCellEditor.Dispose(); this.Invalidate(); - if (!this.IsCellEditing) { + if (!this.IsCellEditing) + { if (this.Focused) this.Select(); this.PauseAnimations(false); @@ -10028,7 +10956,7 @@ namespace BrightIdeasSoftware // to be edited. Otherwise, we remove the control immediately. if (expectingCellEdit) this.RunWhenIdle(toBeRun); - else + else toBeRun(null, null); } @@ -10039,14 +10967,16 @@ namespace BrightIdeasSoftware /// /// Force the hot item to be recalculated /// - public virtual void ClearHotItem() { + public virtual void ClearHotItem() + { this.UpdateHotItem(new Point(-1, -1)); } /// /// Force the hot item to be recalculated /// - public virtual void RefreshHotItem() { + public virtual void RefreshHotItem() + { this.UpdateHotItem(this.PointToClient(Cursor.Position)); } @@ -10055,7 +10985,8 @@ namespace BrightIdeasSoftware /// /// Where is the mouse? /// This is the main entry point for hot item handling - protected virtual void UpdateHotItem(Point pt) { + protected virtual void UpdateHotItem(Point pt) + { this.UpdateHotItem(this.OlvHitTest(pt.X, pt.Y)); } @@ -10064,7 +10995,8 @@ namespace BrightIdeasSoftware /// /// /// This is the main entry point for hot item handling - protected virtual void UpdateHotItem(OlvListViewHitTestInfo hti) { + protected virtual void UpdateHotItem(OlvListViewHitTestInfo hti) + { // We only need to do the work of this method when the list has hot parts // (i.e. some element whose visual appearance changes when under the mouse)? @@ -10091,7 +11023,8 @@ namespace BrightIdeasSoftware this.HotColumnIndex == newHotColumn && this.HotCellHitLocation == newHotCellHitLocation && this.HotCellHitLocationEx == newHotCellHitLocationEx && - this.HotGroup == newHotGroup) { + this.HotGroup == newHotGroup) + { return; } @@ -10120,29 +11053,36 @@ namespace BrightIdeasSoftware if (args.Handled) return; -// System.Diagnostics.Debug.WriteLine(String.Format("Changed hot item: {0}", args)); + // System.Diagnostics.Debug.WriteLine(String.Format("Changed hot item: {0}", args)); this.BeginUpdate(); - try { + try + { this.Invalidate(); if (args.OldHotRowIndex != -1) this.UnapplyHotItem(args.OldHotRowIndex); - if (this.HotRowIndex != -1) { + if (this.HotRowIndex != -1) + { // Virtual lists apply hot item style when fetching their rows - if (this.VirtualMode) { + if (this.VirtualMode) + { this.ClearCachedInfo(); this.RedrawItems(this.HotRowIndex, this.HotRowIndex, true); - } else { + } + else + { this.UpdateHotRow(this.HotRowIndex, this.HotColumnIndex, this.HotCellHitLocation, hti.Item); } } - if (this.UseHotItem && this.HotItemStyleOrDefault.Overlay != null) { + if (this.UseHotItem && this.HotItemStyleOrDefault.Overlay != null) + { this.RefreshOverlays(); } } - finally { + finally + { this.EndUpdate(); } } @@ -10151,7 +11091,8 @@ namespace BrightIdeasSoftware /// Update the given row using the current hot item information /// /// - protected virtual void UpdateHotRow(OLVListItem olvi) { + protected virtual void UpdateHotRow(OLVListItem olvi) + { this.UpdateHotRow(this.HotRowIndex, this.HotColumnIndex, this.HotCellHitLocation, olvi); } @@ -10162,25 +11103,32 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void UpdateHotRow(int rowIndex, int columnIndex, HitTestLocation hitLocation, OLVListItem olvi) { + protected virtual void UpdateHotRow(int rowIndex, int columnIndex, HitTestLocation hitLocation, OLVListItem olvi) + { if (rowIndex < 0 || columnIndex < 0) return; - // System.Diagnostics.Debug.WriteLine(String.Format("UpdateHotRow: {0}, {1}, {2}", rowIndex, columnIndex, hitLocation)); + // System.Diagnostics.Debug.WriteLine(String.Format("UpdateHotRow: {0}, {1}, {2}", rowIndex, columnIndex, hitLocation)); - if (this.UseHyperlinks) { + if (this.UseHyperlinks) + { OLVColumn column = this.GetColumn(columnIndex); OLVListSubItem subItem = olvi.GetSubItem(columnIndex); - if (column.Hyperlink && hitLocation == HitTestLocation.Text && !String.IsNullOrEmpty(subItem.Url)) { + if (column.Hyperlink && hitLocation == HitTestLocation.Text && !String.IsNullOrEmpty(subItem.Url)) + { this.ApplyCellStyle(olvi, columnIndex, this.HyperlinkStyle.Over); this.Cursor = this.HyperlinkStyle.OverCursor ?? Cursors.Default; - } else { + } + else + { this.Cursor = Cursors.Default; } } - if (this.UseHotItem) { - if (!olvi.Selected && olvi.Enabled) { + if (this.UseHotItem) + { + if (!olvi.Selected && olvi.Enabled) + { this.ApplyRowStyle(olvi, this.HotItemStyleOrDefault); } } @@ -10191,7 +11139,8 @@ namespace BrightIdeasSoftware /// /// /// - public virtual void ApplyRowStyle(OLVListItem olvi, IItemStyle style) { + public virtual void ApplyRowStyle(OLVListItem olvi, IItemStyle style) + { if (style == null) return; @@ -10200,28 +11149,34 @@ namespace BrightIdeasSoftware if (style.FontStyle != FontStyle.Regular) font = new Font(font ?? this.Font, style.FontStyle); - if (!Equals(font, olvi.Font)) { + if (!Equals(font, olvi.Font)) + { if (olvi.UseItemStyleForSubItems) olvi.Font = font; - else { + else + { foreach (ListViewItem.ListViewSubItem x in olvi.SubItems) x.Font = font; } } - if (!style.ForeColor.IsEmpty) { + if (!style.ForeColor.IsEmpty) + { if (olvi.UseItemStyleForSubItems) olvi.ForeColor = style.ForeColor; - else { + else + { foreach (ListViewItem.ListViewSubItem x in olvi.SubItems) x.ForeColor = style.ForeColor; } } - if (!style.BackColor.IsEmpty) { + if (!style.BackColor.IsEmpty) + { if (olvi.UseItemStyleForSubItems) olvi.BackColor = style.BackColor; - else { + else + { foreach (ListViewItem.ListViewSubItem x in olvi.SubItems) x.BackColor = style.BackColor; } @@ -10234,7 +11189,8 @@ namespace BrightIdeasSoftware /// /// /// - protected virtual void ApplyCellStyle(OLVListItem olvi, int columnIndex, IItemStyle style) { + protected virtual void ApplyCellStyle(OLVListItem olvi, int columnIndex, IItemStyle style) + { if (style == null) return; @@ -10262,15 +11218,20 @@ namespace BrightIdeasSoftware /// Remove hot item styling from the given row /// /// - protected virtual void UnapplyHotItem(int index) { + protected virtual void UnapplyHotItem(int index) + { this.Cursor = Cursors.Default; // Virtual lists will apply the appropriate formatting when the row is fetched - if (this.VirtualMode) { + if (this.VirtualMode) + { if (index < this.VirtualListSize) this.RedrawItems(index, index, true); - } else { + } + else + { OLVListItem olvi = this.GetItem(index); - if (olvi != null) { + if (olvi != null) + { //this.PostProcessOneRow(index, index, olvi); this.RefreshItem(olvi); } @@ -10286,14 +11247,16 @@ namespace BrightIdeasSoftware /// /// /// - protected override void OnItemDrag(ItemDragEventArgs e) { + protected override void OnItemDrag(ItemDragEventArgs e) + { base.OnItemDrag(e); if (this.DragSource == null) return; Object data = this.DragSource.StartDrag(this, e.Button, (OLVListItem)e.Item); - if (data != null) { + if (data != null) + { DragDropEffects effect = this.DoDragDrop(data, this.DragSource.GetAllowedEffects(data)); this.DragSource.EndDrag(data, effect); } @@ -10303,7 +11266,8 @@ namespace BrightIdeasSoftware /// /// /// - protected override void OnDragEnter(DragEventArgs args) { + protected override void OnDragEnter(DragEventArgs args) + { base.OnDragEnter(args); if (this.DropSink != null) @@ -10314,7 +11278,8 @@ namespace BrightIdeasSoftware /// /// /// - protected override void OnDragOver(DragEventArgs args) { + protected override void OnDragOver(DragEventArgs args) + { base.OnDragOver(args); if (this.DropSink != null) @@ -10325,7 +11290,8 @@ namespace BrightIdeasSoftware /// /// /// - protected override void OnDragDrop(DragEventArgs args) { + protected override void OnDragDrop(DragEventArgs args) + { base.OnDragDrop(args); if (this.DropSink != null) @@ -10336,7 +11302,8 @@ namespace BrightIdeasSoftware /// /// /// - protected override void OnDragLeave(EventArgs e) { + protected override void OnDragLeave(EventArgs e) + { base.OnDragLeave(e); if (this.DropSink != null) @@ -10347,7 +11314,8 @@ namespace BrightIdeasSoftware /// /// /// - protected override void OnGiveFeedback(GiveFeedbackEventArgs args) { + protected override void OnGiveFeedback(GiveFeedbackEventArgs args) + { base.OnGiveFeedback(args); if (this.DropSink != null) @@ -10358,7 +11326,8 @@ namespace BrightIdeasSoftware /// /// /// - protected override void OnQueryContinueDrag(QueryContinueDragEventArgs args) { + protected override void OnQueryContinueDrag(QueryContinueDragEventArgs args) + { base.OnQueryContinueDrag(args); if (this.DropSink != null) @@ -10376,7 +11345,8 @@ namespace BrightIdeasSoftware /// /// A decoration scrolls with the listview. An overlay stays fixed in place. /// - public virtual void AddDecoration(IDecoration decoration) { + public virtual void AddDecoration(IDecoration decoration) + { if (decoration == null) return; this.Decorations.Add(decoration); @@ -10387,7 +11357,8 @@ namespace BrightIdeasSoftware /// Add the given overlay to those on this list and make it appear /// /// The overlay - public virtual void AddOverlay(IOverlay overlay) { + public virtual void AddOverlay(IOverlay overlay) + { if (overlay == null) return; this.Overlays.Add(overlay); @@ -10399,40 +11370,50 @@ namespace BrightIdeasSoftware /// /// A Graphics /// The items that were redrawn and whose decorations should also be redrawn - protected virtual void DrawAllDecorations(Graphics g, List itemsThatWereRedrawn) { + protected virtual void DrawAllDecorations(Graphics g, List itemsThatWereRedrawn) + { g.TextRenderingHint = ObjectListView.TextRenderingHint; g.SmoothingMode = ObjectListView.SmoothingMode; Rectangle contentRectangle = this.ContentRectangle; - if (this.HasEmptyListMsg && this.GetItemCount() == 0) { + if (this.HasEmptyListMsg && this.GetItemCount() == 0) + { this.EmptyListMsgOverlay.Draw(this, g, contentRectangle); } // Let the drop sink draw whatever feedback it likes - if (this.DropSink != null) { + if (this.DropSink != null) + { this.DropSink.DrawFeedback(g, contentRectangle); } // Draw our item and subitem decorations - foreach (OLVListItem olvi in itemsThatWereRedrawn) { - if (olvi.HasDecoration) { - foreach (IDecoration d in olvi.Decorations) { + foreach (OLVListItem olvi in itemsThatWereRedrawn) + { + if (olvi.HasDecoration) + { + foreach (IDecoration d in olvi.Decorations) + { d.ListItem = olvi; d.SubItem = null; d.Draw(this, g, contentRectangle); } } - foreach (OLVListSubItem subItem in olvi.SubItems) { - if (subItem.HasDecoration) { - foreach (IDecoration d in subItem.Decorations) { + foreach (OLVListSubItem subItem in olvi.SubItems) + { + if (subItem.HasDecoration) + { + foreach (IDecoration d in subItem.Decorations) + { d.ListItem = olvi; d.SubItem = subItem; d.Draw(this, g, contentRectangle); } } } - if (this.SelectedRowDecoration != null && olvi.Selected && olvi.Enabled) { + if (this.SelectedRowDecoration != null && olvi.Selected && olvi.Enabled) + { this.SelectedRowDecoration.ListItem = olvi; this.SelectedRowDecoration.SubItem = null; this.SelectedRowDecoration.Draw(this, g, contentRectangle); @@ -10440,18 +11421,22 @@ namespace BrightIdeasSoftware } // Now draw the specifically registered decorations - foreach (IDecoration decoration in this.Decorations) { + foreach (IDecoration decoration in this.Decorations) + { decoration.ListItem = null; decoration.SubItem = null; decoration.Draw(this, g, contentRectangle); } // Finally, draw any hot item decoration - if (this.UseHotItem) { + if (this.UseHotItem) + { IDecoration hotItemDecoration = this.HotItemStyleOrDefault.Decoration; - if (hotItemDecoration != null) { + if (hotItemDecoration != null) + { hotItemDecoration.ListItem = this.GetItem(this.HotRowIndex); - if (hotItemDecoration.ListItem == null || hotItemDecoration.ListItem.Enabled) { + if (hotItemDecoration.ListItem == null || hotItemDecoration.ListItem.Enabled) + { hotItemDecoration.SubItem = hotItemDecoration.ListItem == null ? null : hotItemDecoration.ListItem.GetSubItem(this.HotColumnIndex); hotItemDecoration.Draw(this, g, contentRectangle); } @@ -10460,8 +11445,10 @@ namespace BrightIdeasSoftware // If we are in design mode, we don't want to use the glass panels, // so we draw the background overlays here - if (this.DesignMode) { - foreach (IOverlay overlay in this.Overlays) { + if (this.DesignMode) + { + foreach (IOverlay overlay in this.Overlays) + { overlay.Draw(this, g, contentRectangle); } } @@ -10471,7 +11458,8 @@ namespace BrightIdeasSoftware /// Is the given decoration shown on this list /// /// The overlay - public virtual bool HasDecoration(IDecoration decoration) { + public virtual bool HasDecoration(IDecoration decoration) + { return this.Decorations.Contains(decoration); } @@ -10479,7 +11467,8 @@ namespace BrightIdeasSoftware /// Is the given overlay shown on this list? /// /// The overlay - public virtual bool HasOverlay(IOverlay overlay) { + public virtual bool HasOverlay(IOverlay overlay) + { return this.Overlays.Contains(overlay); } @@ -10490,8 +11479,10 @@ namespace BrightIdeasSoftware /// This is only a temporary hiding -- the overlays will be shown /// the next time the ObjectListView redraws. /// - public virtual void HideOverlays() { - foreach (GlassPanelForm glassPanel in this.glassPanels) { + public virtual void HideOverlays() + { + foreach (GlassPanelForm glassPanel in this.glassPanels) + { glassPanel.HideGlass(); } } @@ -10499,7 +11490,8 @@ namespace BrightIdeasSoftware /// /// Create and configure the empty list msg overlay /// - protected virtual void InitializeEmptyListMsgOverlay() { + protected virtual void InitializeEmptyListMsgOverlay() + { TextOverlay overlay = new TextOverlay(); overlay.Alignment = System.Drawing.ContentAlignment.MiddleCenter; overlay.TextColor = SystemColors.ControlDarkDark; @@ -10512,7 +11504,8 @@ namespace BrightIdeasSoftware /// /// Initialize the standard image and text overlays /// - protected virtual void InitializeStandardOverlays() { + protected virtual void InitializeStandardOverlays() + { this.OverlayImage = new ImageOverlay(); this.AddOverlay(this.OverlayImage); this.OverlayText = new TextOverlay(); @@ -10522,28 +11515,34 @@ namespace BrightIdeasSoftware /// /// Make sure that any overlays are visible. /// - public virtual void ShowOverlays() { + public virtual void ShowOverlays() + { // If we shouldn't show overlays, then don't create glass panels if (!this.ShouldShowOverlays()) return; // Make sure that each overlay has its own glass panels - if (this.Overlays.Count != this.glassPanels.Count) { - foreach (IOverlay overlay in this.Overlays) { + if (this.Overlays.Count != this.glassPanels.Count) + { + foreach (IOverlay overlay in this.Overlays) + { GlassPanelForm glassPanel = this.FindGlassPanelForOverlay(overlay); - if (glassPanel == null) { + if (glassPanel == null) + { glassPanel = new GlassPanelForm(); glassPanel.Bind(this, overlay); this.glassPanels.Add(glassPanel); } } } - foreach (GlassPanelForm glassPanel in this.glassPanels) { + foreach (GlassPanelForm glassPanel in this.glassPanels) + { glassPanel.ShowGlass(); } } - private bool ShouldShowOverlays() { + private bool ShouldShowOverlays() + { // If we are in design mode, we dont show the overlays if (this.DesignMode) return false; @@ -10566,15 +11565,18 @@ namespace BrightIdeasSoftware return true; } - private GlassPanelForm FindGlassPanelForOverlay(IOverlay overlay) { - return this.glassPanels.Find(delegate(GlassPanelForm x) { return x.Overlay == overlay; }); + private GlassPanelForm FindGlassPanelForOverlay(IOverlay overlay) + { + return this.glassPanels.Find(delegate (GlassPanelForm x) { return x.Overlay == overlay; }); } /// /// Refresh the display of the overlays /// - public virtual void RefreshOverlays() { - foreach (GlassPanelForm glassPanel in this.glassPanels) { + public virtual void RefreshOverlays() + { + foreach (GlassPanelForm glassPanel in this.glassPanels) + { glassPanel.Invalidate(); } } @@ -10582,7 +11584,8 @@ namespace BrightIdeasSoftware /// /// Refresh the display of just one overlays /// - public virtual void RefreshOverlay(IOverlay overlay) { + public virtual void RefreshOverlay(IOverlay overlay) + { GlassPanelForm glassPanel = this.FindGlassPanelForOverlay(overlay); if (glassPanel != null) glassPanel.Invalidate(); @@ -10592,7 +11595,8 @@ namespace BrightIdeasSoftware /// Remove the given decoration from this list /// /// The decoration to remove - public virtual void RemoveDecoration(IDecoration decoration) { + public virtual void RemoveDecoration(IDecoration decoration) + { if (decoration == null) return; this.Decorations.Remove(decoration); @@ -10603,12 +11607,14 @@ namespace BrightIdeasSoftware /// Remove the given overlay to those on this list /// /// The overlay - public virtual void RemoveOverlay(IOverlay overlay) { + public virtual void RemoveOverlay(IOverlay overlay) + { if (overlay == null) return; this.Overlays.Remove(overlay); GlassPanelForm glassPanel = this.FindGlassPanelForOverlay(overlay); - if (glassPanel != null) { + if (glassPanel != null) + { this.glassPanels.Remove(glassPanel); glassPanel.Unbind(); glassPanel.Dispose(); @@ -10623,9 +11629,11 @@ namespace BrightIdeasSoftware /// Create a filter that will enact all the filtering currently installed /// on the visible columns. /// - public virtual IModelFilter CreateColumnFilter() { + public virtual IModelFilter CreateColumnFilter() + { List filters = new List(); - foreach (OLVColumn column in this.Columns) { + foreach (OLVColumn column in this.Columns) + { IModelFilter filter = column.ValueBasedFilter; if (filter != null) filters.Add(filter); @@ -10640,12 +11648,13 @@ namespace BrightIdeasSoftware /// /// /// - virtual protected IEnumerable FilterObjects(IEnumerable originalObjects, IModelFilter aModelFilter, IListFilter aListFilter) { + virtual protected IEnumerable FilterObjects(IEnumerable originalObjects, IModelFilter aModelFilter, IListFilter aListFilter) + { // Being cautious originalObjects = originalObjects ?? new ArrayList(); // Tell the world to filter the objects. If they do so, don't do anything else -// ReSharper disable PossibleMultipleEnumeration + // ReSharper disable PossibleMultipleEnumeration FilterEventArgs args = new FilterEventArgs(originalObjects); this.OnFilter(args); if (args.FilteredObjects != null) @@ -10656,9 +11665,11 @@ namespace BrightIdeasSoftware originalObjects = aListFilter.Filter(originalObjects); // Apply the object filter if there is one - if (aModelFilter != null) { + if (aModelFilter != null) + { ArrayList filteredObjects = new ArrayList(); - foreach (object model in originalObjects) { + foreach (object model in originalObjects) + { if (aModelFilter.Filter(model)) filteredObjects.Add(model); } @@ -10666,14 +11677,16 @@ namespace BrightIdeasSoftware } return originalObjects; -// ReSharper restore PossibleMultipleEnumeration + // ReSharper restore PossibleMultipleEnumeration } /// /// Remove all column filtering. /// - public virtual void ResetColumnFiltering() { - foreach (OLVColumn column in this.Columns) { + public virtual void ResetColumnFiltering() + { + foreach (OLVColumn column in this.Columns) + { column.ValuesChosenForFiltering.Clear(); } this.UpdateColumnFiltering(); @@ -10683,7 +11696,8 @@ namespace BrightIdeasSoftware /// Update the filtering of this ObjectListView based on the value filtering /// defined in each column /// - public virtual void UpdateColumnFiltering() { + public virtual void UpdateColumnFiltering() + { //List filters = new List(); //IModelFilter columnFilter = this.CreateColumnFilter(); //if (columnFilter != null) @@ -10694,11 +11708,13 @@ namespace BrightIdeasSoftware if (this.AdditionalFilter == null) this.ModelFilter = this.CreateColumnFilter(); - else { + else + { IModelFilter columnFilter = this.CreateColumnFilter(); if (columnFilter == null) this.ModelFilter = this.AdditionalFilter; - else { + else + { List filters = new List(); filters.Add(columnFilter); filters.Add(this.AdditionalFilter); @@ -10710,19 +11726,22 @@ namespace BrightIdeasSoftware /// /// When some setting related to filtering changes, this method is called. /// - protected virtual void UpdateFiltering() { + protected virtual void UpdateFiltering() + { this.BuildList(true); } /// /// Update all renderers with the currently installed model filter /// - protected virtual void NotifyNewModelFilter() { + protected virtual void NotifyNewModelFilter() + { IFilterAwareRenderer filterAware = this.DefaultRenderer as IFilterAwareRenderer; if (filterAware != null) filterAware.Filter = this.ModelFilter; - foreach (OLVColumn column in this.AllColumns) { + foreach (OLVColumn column in this.AllColumns) + { filterAware = column.Renderer as IFilterAwareRenderer; if (filterAware != null) filterAware.Filter = this.ModelFilter; @@ -10738,7 +11757,8 @@ namespace BrightIdeasSoftware /// /// The model /// The checkedness of the model. Defaults to unchecked. - protected virtual CheckState GetPersistentCheckState(object model) { + protected virtual CheckState GetPersistentCheckState(object model) + { CheckState state; if (model != null && this.CheckStateMap.TryGetValue(model, out state)) return state; @@ -10751,7 +11771,8 @@ namespace BrightIdeasSoftware /// The model to be remembered /// The model's checkedness /// The state given to the method - protected virtual CheckState SetPersistentCheckState(object model, CheckState state) { + protected virtual CheckState SetPersistentCheckState(object model, CheckState state) + { if (model == null) return CheckState.Unchecked; @@ -10762,7 +11783,8 @@ namespace BrightIdeasSoftware /// /// Forget any persistent checkbox state /// - protected virtual void ClearPersistentCheckState() { + protected virtual void ClearPersistentCheckState() + { this.CheckStateMap = null; } diff --git a/ObjectListView/Rendering/Renderers.cs b/ObjectListView/Rendering/Renderers.cs index d54ca689..e6bce219 100644 --- a/ObjectListView/Rendering/Renderers.cs +++ b/ObjectListView/Rendering/Renderers.cs @@ -518,7 +518,7 @@ namespace BrightIdeasSoftware { [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public ImageList ImageListOrDefault { - get { return this.ImageList ?? this.ListView.SmallImageList; } + get { return this.ImageList ?? this.ListView.GetSmallImageList(); } } /// @@ -809,7 +809,7 @@ namespace BrightIdeasSoftware { /// /// protected virtual Size CalculatePrimaryCheckBoxSize(Graphics g) { - if (!this.ListView.CheckBoxes || !this.ColumnIsPrimary) + if (!this.ListView.GetCheckBoxes() || !this.ColumnIsPrimary) return Size.Empty; Size size = this.CalculateCheckBoxSize(g); @@ -1299,7 +1299,7 @@ namespace BrightIdeasSoftware { int width = 0; // Did they hit a check box on the primary column? - if (this.ColumnIsPrimary && this.ListView.CheckBoxes) { + if (this.ColumnIsPrimary && this.ListView.GetCheckBoxes()) { Size checkBoxSize = this.CalculateCheckBoxSize(g); int checkBoxTop = this.AlignVertically(r, checkBoxSize.Height); Rectangle r3 = new Rectangle(r.X, checkBoxTop, checkBoxSize.Width, checkBoxSize.Height); @@ -1635,7 +1635,7 @@ namespace BrightIdeasSoftware { /// Bounds of the cell protected virtual void DrawImageAndText(Graphics g, Rectangle r) { int offset = 0; - if (this.ListView.CheckBoxes && this.ColumnIsPrimary) { + if (this.ListView.GetCheckBoxes() && this.ColumnIsPrimary) { offset = this.DrawCheckBox(g, r) + 6; r.X += offset; r.Width -= offset; diff --git a/ObjectListView/TreeListView.cs b/ObjectListView/TreeListView.cs index 8b0aa943..c7c971be 100644 --- a/ObjectListView/TreeListView.cs +++ b/ObjectListView/TreeListView.cs @@ -193,7 +193,7 @@ namespace BrightIdeasSoftware // ReSharper restore DoNotCallOverridableMethodsInConstructor // This improves hit detection even if we don't have any state image - this.SmallImageList = new ImageList(); + this.SetSmallImageList(new ImageList()); // this.StateImageList.ImageSize = new Size(6, 6); } @@ -364,7 +364,7 @@ namespace BrightIdeasSoftware return; this.hierarchicalCheckboxes = value; - this.CheckBoxes = value; + this.SetCheckBoxes(value); if (value) this.TriStateCheckBoxes = false; } diff --git a/ObjectListView/Utilities/ColumnSelectionForm.Designer.cs b/ObjectListView/Utilities/ColumnSelectionForm.Designer.cs index e8e520e6..29ebc7df 100644 --- a/ObjectListView/Utilities/ColumnSelectionForm.Designer.cs +++ b/ObjectListView/Utilities/ColumnSelectionForm.Designer.cs @@ -125,7 +125,7 @@ namespace BrightIdeasSoftware | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.objectListView1.CellEditActivation = BrightIdeasSoftware.ObjectListView.CellEditActivateMode.SingleClick; - this.objectListView1.CheckBoxes = true; + this.objectListView1.SetCheckBoxes(true); this.objectListView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.olvColumn1}); this.objectListView1.FullRowSelect = true; diff --git a/ObjectListView/VirtualObjectListView.cs b/ObjectListView/VirtualObjectListView.cs index 36ea12bf..9661d338 100644 --- a/ObjectListView/VirtualObjectListView.cs +++ b/ObjectListView/VirtualObjectListView.cs @@ -175,7 +175,7 @@ namespace BrightIdeasSoftware public override IList CheckedObjects { get { // If we aren't should checkboxes, then no objects can be checked - if (!this.CheckBoxes) + if (!this.GetCheckBoxes()) return new ArrayList(); // If the data source has somehow vanished, we can't do anything @@ -199,7 +199,7 @@ namespace BrightIdeasSoftware return objects; } set { - if (!this.CheckBoxes) + if (!this.GetCheckBoxes()) return; // If a custom check state getter is install, we can't use our check state management