Skip to content

Commit 025aab8

Browse files
author
grammarian
committed
- v2.9.1
- Added CellRendererGetter to allow each cell to have a different renderer. - Obsolete properties are no longer code-gen'ed. - Fixed a few small bugs git-svn-id: https://svn.code.sf.net/p/objectlistview/code/cs/trunk@804 0bec5ed8-b53f-49e6-9885-ce7bc93af311
1 parent 13a0b8b commit 025aab8

File tree

6 files changed

+97
-33
lines changed

6 files changed

+97
-33
lines changed

ObjectListView/CellEditing/CellEditKeyEngine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ protected ObjectListView ListView {
249249
/// </summary>
250250
protected OLVListItem ItemBeingEdited {
251251
get {
252-
return this.ListView.CellEditEventArgs.ListViewItem;
252+
return (this.ListView == null || this.ListView.CellEditEventArgs == null) ? null : this.ListView.CellEditEventArgs.ListViewItem;
253253
}
254254
}
255255

@@ -258,7 +258,7 @@ protected OLVListItem ItemBeingEdited {
258258
/// </summary>
259259
protected int SubItemIndexBeingEdited {
260260
get {
261-
return this.ListView.CellEditEventArgs.SubItemIndex;
261+
return (this.ListView == null || this.ListView.CellEditEventArgs == null) ? -1 : this.ListView.CellEditEventArgs.SubItemIndex;
262262
}
263263
}
264264

ObjectListView/Implementation/Delegates.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
* Date: 31-March-2011 5:53 pm
66
*
77
* Change log:
8+
* v2.10
9+
* 2015-12-30 JPP - Added CellRendererGetterDelegate
10+
* v2.?
811
* 2011-03-31 JPP - Split into its own file
912
*
10-
* Copyright (C) 2011-2014 Phillip Piper
13+
* Copyright (C) 2011-2015 Phillip Piper
1114
*
1215
* This program is free software: you can redistribute it and/or modify
1316
* it under the terms of the GNU General Public License as published by
@@ -26,8 +29,6 @@
2629
*/
2730

2831
using System;
29-
using System.Collections.Generic;
30-
using System.Text;
3132
using System.Windows.Forms;
3233
using System.Drawing;
3334

@@ -89,6 +90,11 @@ namespace BrightIdeasSoftware {
8990
/// <returns></returns>
9091
public delegate bool BooleanCheckStatePutterDelegate(Object rowObject, bool newValue);
9192

93+
/// <summary>
94+
/// These delegates are used to get the renderer for a particular cell
95+
/// </summary>
96+
public delegate IRenderer CellRendererGetterDelegate(Object rowObject, OLVColumn column);
97+
9298
/// <summary>
9399
/// The callbacks for RightColumnClick events
94100
/// </summary>
@@ -120,7 +126,7 @@ namespace BrightIdeasSoftware {
120126
/// These delegates are used to get the tooltip for a column header
121127
/// </summary>
122128
public delegate String HeaderToolTipGetterDelegate(OLVColumn column);
123-
129+
124130
/// <summary>
125131
/// These delegates are used to fetch the image selector that should be used
126132
/// to choose an image for this column.

ObjectListView/Implementation/OLVListSubItem.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,23 @@ public Object ImageSelector {
140140
/// <summary>
141141
/// Gets or sets the url that should be invoked when this subitem is clicked
142142
/// </summary>
143-
public string Url {
143+
public string Url
144+
{
144145
get { return this.url; }
145146
set { this.url = value; }
146147
}
147148
private string url;
148149

150+
/// <summary>
151+
/// Gets or sets whether this cell is selected
152+
/// </summary>
153+
public bool Selected
154+
{
155+
get { return this.selected; }
156+
set { this.selected = value; }
157+
}
158+
private bool selected;
159+
149160
#endregion
150161

151162
#region Implementation Properties

ObjectListView/ObjectListView.cs

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
* Date: 9/10/2006 11:15 AM
66
*
77
* Change log
8+
* v2.9.1
9+
* 2015-12-30 JPP - Added CellRendererGetter to allow each cell to have a different renderer.
10+
* - Obsolete properties are no longer code-gen'ed.
11+
*
812
* v2.9.0
913
* 2015-08-22 JPP - Allow selected row back/fore colours to be specified for each row
1014
* - Renamed properties related to selection colours:
@@ -548,7 +552,7 @@
548552
* TO DO:
549553
* - Support undocumented group features: subseted groups, group footer items
550554
*
551-
* Copyright (C) 2006-2015 Phillip Piper
555+
* Copyright (C) 2006-2016 Phillip Piper
552556
*
553557
* This program is free software: you can redistribute it and/or modify
554558
* it under the terms of the GNU General Public License as published by
@@ -1035,7 +1039,7 @@ public virtual bool CellEditUseWholeCell {
10351039
get { return cellEditUseWholeCell; }
10361040
set { cellEditUseWholeCell = value; }
10371041
}
1038-
private bool cellEditUseWholeCell = false;
1042+
private bool cellEditUseWholeCell;
10391043

10401044
/// <summary>
10411045
/// Gets or sets the engine that will handle key presses during a cell edit operation.
@@ -1410,6 +1414,17 @@ public IRenderer DefaultRenderer {
14101414
}
14111415
private IRenderer defaultRenderer = new HighlightTextRenderer();
14121416

1417+
/// <summary>
1418+
/// Get the renderer to be used to draw the given cell.
1419+
/// </summary>
1420+
/// <param name="model">The row model for the row</param>
1421+
/// <param name="column">The column to be drawn</param>
1422+
/// <returns>The renderer used for drawing a cell. Must not return null.</returns>
1423+
public IRenderer GetCellRenderer(object model, OLVColumn column) {
1424+
IRenderer renderer = this.CellRendererGetter == null ? null : this.CellRendererGetter(model, column);
1425+
return renderer ?? column.Renderer ?? this.DefaultRenderer;
1426+
}
1427+
14131428
/// <summary>
14141429
/// Gets or sets the style that will be applied to disabled items.
14151430
/// </summary>
@@ -2141,29 +2156,33 @@ public virtual Color SelectedForeColorOrDefault {
21412156
}
21422157
}
21432158

2159+
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
21442160
[Obsolete("Use SelectedBackColor instead")]
21452161
public virtual Color HighlightBackgroundColor { get { return this.SelectedBackColor; } set { this.SelectedBackColor = value; } }
21462162

21472163
[Obsolete("Use SelectedBackColorOrDefault instead")]
21482164
public virtual Color HighlightBackgroundColorOrDefault { get { return this.SelectedBackColorOrDefault; } }
21492165

2166+
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
21502167
[Obsolete("Use SelectedForeColor instead")]
21512168
public virtual Color HighlightForegroundColor { get { return this.SelectedForeColor; } set { this.SelectedForeColor = value; } }
21522169

21532170
[Obsolete("Use SelectedForeColorOrDefault instead")]
21542171
public virtual Color HighlightForegroundColorOrDefault { get { return this.SelectedForeColorOrDefault; } }
21552172

2156-
// [Obsolete("Use UnfocusedSelectedBackColor instead")]
2157-
// public virtual Color UnfocusedHighlightBackgroundColor { get { return this.UnfocusedSelectedBackColor; } set { this.UnfocusedSelectedBackColor = value; } }
2158-
//
2159-
// [Obsolete("Use UnfocusedSelectedBackColorOrDefault instead")]
2160-
// public virtual Color UnfocusedHighlightBackgroundColorOrDefault { get { return this.UnfocusedSelectedBackColorOrDefault; } }
2161-
//
2162-
// [Obsolete("Use UnfocusedSelectedForeColor instead")]
2163-
// public virtual Color UnfocusedHighlightForegroundColor { get { return this.UnfocusedSelectedForeColor; } set { this.UnfocusedSelectedForeColor = value; } }
2164-
//
2165-
// [Obsolete("Use UnfocusedSelectedForeColorOrDefault instead")]
2166-
// public virtual Color UnfocusedHighlightForegroundColorOrDefault { get { return this.UnfocusedSelectedForeColorOrDefault; } }
2173+
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2174+
[Obsolete("Use UnfocusedSelectedBackColor instead")]
2175+
public virtual Color UnfocusedHighlightBackgroundColor { get { return this.UnfocusedSelectedBackColor; } set { this.UnfocusedSelectedBackColor = value; } }
2176+
2177+
[Obsolete("Use UnfocusedSelectedBackColorOrDefault instead")]
2178+
public virtual Color UnfocusedHighlightBackgroundColorOrDefault { get { return this.UnfocusedSelectedBackColorOrDefault; } }
2179+
2180+
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
2181+
[Obsolete("Use UnfocusedSelectedForeColor instead")]
2182+
public virtual Color UnfocusedHighlightForegroundColor { get { return this.UnfocusedSelectedForeColor; } set { this.UnfocusedSelectedForeColor = value; } }
2183+
2184+
[Obsolete("Use UnfocusedSelectedForeColorOrDefault instead")]
2185+
public virtual Color UnfocusedHighlightForegroundColorOrDefault { get { return this.UnfocusedSelectedForeColorOrDefault; } }
21672186

21682187
/// <summary>
21692188
/// Gets or sets whether or not hidden columns should be included in the text representation
@@ -3373,6 +3392,7 @@ public bool UseCellFormatEvents {
33733392
DefaultValue(false)]
33743393
public bool UseCustomSelectionColors {
33753394
get { return false; }
3395+
// ReSharper disable once ValueParameterNotUsed
33763396
set { }
33773397
}
33783398

@@ -3722,6 +3742,27 @@ public virtual bool CanUseApplicationIdle {
37223742
}
37233743
private bool canUseApplicationIdle = true;
37243744

3745+
/// <summary>
3746+
/// This delegate fetches the renderer for a particular cell.
3747+
/// </summary>
3748+
/// <remarks>
3749+
/// <para>
3750+
/// If this returns null (or is not installed), the renderer for the column will be used.
3751+
/// If the column renderer is null, then <seealso cref="DefaultRenderer"/> will be used.
3752+
/// </para>
3753+
/// <para>
3754+
/// This is called every time any cell is drawn. It must be efficient!
3755+
/// </para>
3756+
/// </remarks>
3757+
[Browsable(false),
3758+
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
3759+
public virtual CellRendererGetterDelegate CellRendererGetter
3760+
{
3761+
get { return this.cellRendererGetter; }
3762+
set { this.cellRendererGetter = value; }
3763+
}
3764+
private CellRendererGetterDelegate cellRendererGetter;
3765+
37253766
/// <summary>
37263767
/// This delegate is called when the list wants to show a tooltip for a particular cell.
37273768
/// The delegate should return the text to display, or null to use the default behavior
@@ -4229,7 +4270,7 @@ public virtual void BuildList(bool shouldPreserveState) {
42294270
this.TopItemIndex = previousTopIndex;
42304271
}
42314272

4232-
System.Diagnostics.Debug.WriteLine(String.Format("PERF - Building list for {2} objects took {0}ms / {1} ticks", sw.ElapsedMilliseconds, sw.ElapsedTicks, this.GetItemCount()));
4273+
// System.Diagnostics.Debug.WriteLine(String.Format("PERF - Building list for {2} objects took {0}ms / {1} ticks", sw.ElapsedMilliseconds, sw.ElapsedTicks, this.GetItemCount()));
42334274
}
42344275

42354276
/// <summary>
@@ -4909,7 +4950,9 @@ protected virtual void CalculateOwnerDrawnHitTest(OlvListViewHitTestInfo hti, in
49094950
return;
49104951

49114952
// Which renderer was responsible for drawing that point
4912-
IRenderer renderer = this.View == View.Details ? (hti.Column.Renderer ?? this.DefaultRenderer) : this.ItemRenderer;
4953+
IRenderer renderer = this.View == View.Details
4954+
? this.GetCellRenderer(hti.RowObject, hti.Column)
4955+
: this.ItemRenderer;
49134956

49144957
// We can't decide who was responsible. Give up
49154958
if (renderer == null)
@@ -9039,12 +9082,14 @@ protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e) {
90399082
return;
90409083
}
90419084

9085+
object rowObject = ((OLVListItem)e.Item).RowObject;
9086+
90429087
// Calculate where the subitem should be drawn
90439088
Rectangle r = e.Bounds;
90449089

90459090
// Get the special renderer for this column. If there isn't one, use the default draw mechanism.
90469091
OLVColumn column = this.GetColumn(e.ColumnIndex);
9047-
IRenderer renderer = column.Renderer ?? this.DefaultRenderer;
9092+
IRenderer renderer = this.GetCellRenderer(rowObject, column);
90489093

90499094
// Get a graphics context for the renderer to use.
90509095
// But we have more complications. Virtual lists have a nasty habit of drawing column 0
@@ -9060,7 +9105,7 @@ protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e) {
90609105
g.SmoothingMode = ObjectListView.SmoothingMode;
90619106

90629107
// Finally, give the renderer a chance to draw something
9063-
e.DrawDefault = !renderer.RenderSubItem(e, g, r, ((OLVListItem)e.Item).RowObject);
9108+
e.DrawDefault = !renderer.RenderSubItem(e, g, r, rowObject);
90649109

90659110
if (!e.DrawDefault)
90669111
buffer.Render();
@@ -9507,7 +9552,7 @@ public Rectangle CalculateCellEditorBounds(OLVListItem item, int subItemIndex, S
95079552
/// <returns>A rectangle that is the bounds of the cell editor</returns>
95089553
protected Rectangle CalculateCellEditorBoundsOwnerDrawn(OLVListItem item, int subItemIndex, Rectangle r, Size preferredSize) {
95099554
IRenderer renderer = this.View == View.Details
9510-
? (this.GetColumn(subItemIndex).Renderer ?? this.DefaultRenderer)
9555+
? this.GetCellRenderer(item.RowObject, this.GetColumn(subItemIndex))
95119556
: this.ItemRenderer;
95129557

95139558
if (renderer == null)

ObjectListView/ObjectListView2012.nuspec

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
<metadata>
44
<id>ObjectListView.Official</id>
55
<title>ObjectListView (Official)</title>
6-
<version>2.9.0</version>
6+
<version>2.9.1</version>
77
<authors>Phillip Piper</authors>
88
<owners>Phillip Piper</owners>
99
<licenseUrl>http://www.gnu.org/licenses/gpl.html</licenseUrl>
1010
<projectUrl>http://objectlistview.sourceforge.net</projectUrl>
1111
<iconUrl>http://objectlistview.sourceforge.net/cs/_static/index-icon.png</iconUrl>
1212
<requireLicenseAcceptance>true</requireLicenseAcceptance>
1313
<summary>ObjectListView is a .NET ListView wired on caffeine, guarana and steroids.</summary>
14-
<description>ObjectListView is a .NET ListView wired on caffeine, guarana and steroids. More calmly, it is a C# wrapper around a .NET ListView, which makes the ListView much easier to use and teaches it lots of neat new tricks.</description>
15-
<releaseNotes>V2.9 adds buttons to cells, fixed some formatting bugs, and completely rewrote the demo to be much easier to understand.</releaseNotes>
16-
<copyright>Copyright 2006-2015 Bright Ideas Software</copyright>
14+
<description>ObjectListView is a .NET ListView wired on caffeine, guarana and steroids.
15+
More calmly, it is a C# wrapper around a .NET ListView, which makes the ListView much easier to use and teaches it lots of neat new tricks.</description>
16+
<releaseNotes>v2.9.1 Added CellRendererGetter to allow each cell to have a different renderer, plus Fixes a few small bugs.
17+
v2.9 adds buttons to cells, fixed some formatting bugs, and completely rewrote the demo to be much easier to understand.</releaseNotes>
18+
<copyright>Copyright 2006-2016 Bright Ideas Software</copyright>
1719
<tags>.Net WinForms Net20 Net40 ListView Controls</tags>
1820
</metadata>
1921
</package>

ObjectListView/Properties/AssemblyInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("Bright Ideas Software")]
1111
[assembly: AssemblyProduct("ObjectListView")]
12-
[assembly: AssemblyCopyright("Copyright © 2006-2015")]
12+
[assembly: AssemblyCopyright("Copyright © 2006-2016")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -30,7 +30,7 @@
3030
//
3131
// You can specify all the values or you can default the Revision and Build Numbers
3232
// by using the '*' as shown below:
33-
[assembly: AssemblyVersion("2.9.0.*")]
34-
[assembly: AssemblyFileVersion("2.9.0.0")]
35-
[assembly: AssemblyInformationalVersion("2.9.0")]
33+
[assembly: AssemblyVersion("2.9.1.*")]
34+
[assembly: AssemblyFileVersion("2.9.1.0")]
35+
[assembly: AssemblyInformationalVersion("2.9.1")]
3636
[assembly: System.CLSCompliant(true)]

0 commit comments

Comments
 (0)