Skip to content

Commit

Permalink
Implemented Filter Feature for all Header Renderes
Browse files Browse the repository at this point in the history
Issue: #18
  • Loading branch information
schoetbi committed Jul 12, 2016
1 parent 842a574 commit 5a368b5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Models/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7116,7 +7116,7 @@ protected override void OnMouseDown(MouseEventArgs e)
// If the mouse is over the filter button then do nothing here - filter buttons are handled in the click event
if (this.EnableFilters && this.ColumnModel.Columns[column].Filterable)
{
ColumnHeaderRegion colRegion = this.HeaderRenderer.HitTest(e.X, e.Y);
ColumnHeaderRegion colRegion = this.HeaderRenderer.GetColumnHeaderRegion(e.X, e.Y);

if (colRegion == ColumnHeaderRegion.FilterButton)
{
Expand Down Expand Up @@ -7751,7 +7751,7 @@ protected override void OnMouseClick(MouseEventArgs e)
if (this.EnableFilters && this.ColumnModel.Columns[hotColumn].Filterable)
{
Point client = this.DisplayRectToClient(e.X, e.Y);
ColumnHeaderRegion region = this.HeaderRenderer.HitTest(client.X, client.Y);
ColumnHeaderRegion region = this.HeaderRenderer.GetColumnHeaderRegion(client.X, client.Y);

if (region == ColumnHeaderRegion.FilterButton)
{
Expand Down
38 changes: 33 additions & 5 deletions Renderers/FlatHeaderRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

using XPTable.Events;
using XPTable.Models;
Expand Down Expand Up @@ -86,7 +87,17 @@ protected override void OnPaint(PaintHeaderEventArgs e)
}

Rectangle textRect = this.ClientRectangle;
Rectangle imageRect = Rectangle.Empty;

if (e.Column.Filterable)
{
Rectangle filterRect = this.CalcFilterRect();

textRect.Width -= filterRect.Width;

ThemeManager.DrawComboBoxButton(e.Graphics, filterRect, ComboBoxState.Normal);
}

Rectangle imageRect = Rectangle.Empty;

int imageWidth = 0;
int arrowWidth = 0;
Expand Down Expand Up @@ -129,7 +140,7 @@ protected override void OnPaint(PaintHeaderEventArgs e)
arrowWidth = arrowRect.Width;
}

if (e.Column.Text != null && e.Column.Text.Length > 0 && textRect.Width > 0)
if (!string.IsNullOrEmpty(e.Column.Text) && textRect.Width > 0)
{
if (e.Column.Enabled)
{
Expand Down Expand Up @@ -161,8 +172,25 @@ protected override void OnPaint(PaintHeaderEventArgs e)
}
}

#endregion
#endregion

#endregion
}
#endregion

/// <summary>
/// Returns a ColumnHeaderRegion value that represents the header region at the specified client coordinates
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public override ColumnHeaderRegion GetColumnHeaderRegion(int x, int y)
{
Rectangle filterRect = this.CalcFilterRect();
if (filterRect.Contains(x, y))
{
return ColumnHeaderRegion.FilterButton;
}

return ColumnHeaderRegion.ColumnTitle;
}
}
}
35 changes: 31 additions & 4 deletions Renderers/GradientHeaderRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

using XPTable.Events;
using XPTable.Models;
Expand Down Expand Up @@ -217,7 +218,16 @@ protected override void OnPaint(PaintHeaderEventArgs e)
}

Rectangle textRect = this.ClientRectangle;
Rectangle imageRect = Rectangle.Empty;
if (e.Column.Filterable)
{
Rectangle filterRect = this.CalcFilterRect();

textRect.Width -= filterRect.Width;

ThemeManager.DrawComboBoxButton(e.Graphics, filterRect, ComboBoxState.Normal);
}

Rectangle imageRect = Rectangle.Empty;

int imageWidth = 0;
int arrowWidth = 0;
Expand Down Expand Up @@ -304,8 +314,25 @@ protected override void OnPaint(PaintHeaderEventArgs e)
}
}

#endregion
#endregion

#endregion
}
#endregion

/// <summary>
/// Returns a ColumnHeaderRegion value that represents the header region at the specified client coordinates
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public override ColumnHeaderRegion GetColumnHeaderRegion(int x, int y)
{
Rectangle filterRect = this.CalcFilterRect();
if (filterRect.Contains(x, y))
{
return ColumnHeaderRegion.FilterButton;
}

return ColumnHeaderRegion.ColumnTitle;
}
}
}
2 changes: 1 addition & 1 deletion Renderers/HeaderRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ protected virtual void DrawSortArrow(Graphics g, Rectangle drawRect, SortOrder d
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public virtual ColumnHeaderRegion HitTest(int x, int y)
public virtual ColumnHeaderRegion GetColumnHeaderRegion(int x, int y)
{
// This base class does not render filter buttons

Expand Down
2 changes: 1 addition & 1 deletion Renderers/IHeaderRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ public interface IHeaderRenderer : IRenderer
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
ColumnHeaderRegion HitTest(int x, int y);
ColumnHeaderRegion GetColumnHeaderRegion(int x, int y);
}
}
11 changes: 4 additions & 7 deletions Renderers/XPHeaderRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,13 @@ protected override void OnPaint(PaintHeaderEventArgs e)
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public override ColumnHeaderRegion HitTest(int x, int y)
public override ColumnHeaderRegion GetColumnHeaderRegion(int x, int y)
{
Rectangle filterRect = this.CalcFilterRect();

bool contains = filterRect.Contains(x, y);

//Console.WriteLine("HitTest ({0}, {1}) = {2} [{3}]", x, y, contains, filterRect);

if (contains)
if (filterRect.Contains(x, y))
{
return ColumnHeaderRegion.FilterButton;
}

return ColumnHeaderRegion.ColumnTitle;
}
Expand Down

0 comments on commit 5a368b5

Please sign in to comment.