Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HyperLinkCell.cs #318

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 42 additions & 94 deletions ReoGrid/CellTypes/HyperLinkCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,13 @@ public class HyperlinkCell : CellBody
/// </summary>
public string LinkURL { get; set; }

/// <summary>
/// Create hyperlink cell body instance.
/// </summary>
public HyperlinkCell()
: this(null, true)
{
}

/// <summary>
/// Create instane of hyperlink cell body with specified navigation url and AutoNavigate property.
/// </summary>
/// <param name="navigationURL">Navigation url redirected to when hyperlink clicked. (Default is emtpy)</param>
public HyperlinkCell(string navigationURL)
: this(navigationURL, true)
{
}

/// <summary>
/// Create instane of hyperlink cell body with specified navigation url and AutoNavigate property.
/// </summary>
/// <param name="navigationURL">Navigation url redirected to when hyperlink clicked. (Default is emtpy)</param>
/// <param name="autoNavigate">Determine whether or not redirect to specified url
/// when hyperlink clicked automatically. (Default is true)</param>
public HyperlinkCell(string navigationURL, bool autoNavigate)
public HyperlinkCell(string navigationURL = null, bool autoNavigate = true)
{
this.ActivateColor = SolidColor.Red;
this.LinkColor = SolidColor.Blue;
Expand All @@ -96,18 +79,9 @@ public HyperlinkCell(string navigationURL, bool autoNavigate)
}

/// <summary>
/// Determine whether or not the hyperlink is in pressed status.
/// Determine whether or not the mouse is over the hyperlink.
/// </summary>
public bool IsPressed { get; set; }

/// <summary>
/// Handle event when the cell of this body entered edit mode.
/// </summary>
/// <returns>True to allow edit; False to disallow edit.</returns>
public override bool OnStartEdit()
{
return !this.IsPressed;
}
public bool IsOverLink { get; set; }

/// <summary>
/// Initialize cell body when set up into a cell.
Expand Down Expand Up @@ -137,11 +111,12 @@ public override void OnSetup(Cell cell)
/// <returns>True if event has been handled.</returns>
public override bool OnMouseDown(CellMouseEventArgs e)
{
this.IsPressed = true;

e.Cell.Style.TextColor = ActivateColor;
if (this.IsOverLink)
{
e.Cell.Style.TextColor = ActivateColor;
}

return true;
return base.OnMouseDown(e);
}

/// <summary>
Expand All @@ -151,95 +126,68 @@ public override bool OnMouseDown(CellMouseEventArgs e)
/// <returns>True if event has been handled.</returns>
public override bool OnMouseUp(CellMouseEventArgs e)
{
if (this.IsPressed)
if (this.IsOverLink)
{
if (this.Bounds.Contains(e.RelativePosition))
{
this.PerformClick();
}
this.IsOverLink = false;
e.Cell.Style.TextColor = VisitedColor;
this.PerformClick();
return true;
}

this.IsPressed = false;

e.Cell.Style.TextColor = VisitedColor;

return true;
return base.OnMouseUp(e);
}

/// <summary>
/// Change color of hyperlink to hover-status when mouse moved into the cell.
/// Determine whether the mouse is over the link and change the cursor accordingly.
/// </summary>
/// <param name="e">Event argument of cell body mouse-enter.</param>
/// <returns>True if event has been handled.</returns>
public override bool OnMouseEnter(CellMouseEventArgs e)
{
e.Worksheet.controlAdapter.ChangeSelectionCursor(CursorStyle.Hand);
return false;
}

/// <summary>
/// Restore color of hyperlink from hover-status when mouse leaved from cell.
/// </summary>
/// <param name="e">Argument of mouse leaving event.</param>
/// <returns>True if this event has been handled; Otherwise return false.</returns>
public override bool OnMouseLeave(CellMouseEventArgs e)
{
// change current cursor to hand
e.Worksheet.ControlAdapter.ChangeSelectionCursor(CursorStyle.PlatformDefault);
return false;
}

/// <summary>
/// Handle keyboard down event.
/// </summary>
/// <param name="keyCode">Virtual keys code that is converted from system platform.</param>
/// <returns>True if event has been handled; Otherwise return false.</returns>
public override bool OnKeyDown(KeyCode keyCode)
public override bool OnMouseMove(CellMouseEventArgs e)
{
if (keyCode == KeyCode.Space)
if (e.Cell.TextBounds.Contains(e.AbsolutePosition))
{
this.IsPressed = true;
this.Cell.Style.TextColor = ActivateColor;

return true;
if (!this.IsOverLink)
{
this.IsOverLink = true;
e.Worksheet.controlAdapter.ChangeSelectionCursor(CursorStyle.Hand);
}
}
else
{
return false;
if (this.IsOverLink)
{
this.IsOverLink = false;
e.Worksheet.controlAdapter.ChangeSelectionCursor(CursorStyle.PlatformDefault);
}
}
}

return base.OnMouseMove(e);
}

/// <summary>
/// Handle keyboard up event.
/// Restore color of hyperlink from hover-status when mouse leaved from cell.
/// </summary>
/// <param name="keyCode">Virtual keys code that is converted from system platform.</param>
/// <returns>True if event has been handled; Otherwise return false;</returns>
public override bool OnKeyUp(KeyCode keyCode)
/// <param name="e">Argument of mouse leaving event.</param>
/// <returns>True if this event has been handled; Otherwise return false.</returns>
public override bool OnMouseLeave(CellMouseEventArgs e)
{
if (IsPressed)
{
this.IsPressed = false;

this.PerformClick();

this.Cell.Style.TextColor = VisitedColor;

return true;
}
else
// change current cursor to hand
if (this.IsOverLink)
{
return false;
this.IsOverLink = false;
e.Worksheet.controlAdapter.ChangeSelectionCursor(CursorStyle.PlatformDefault);
}
return base.OnMouseLeave(e);
}

/// <summary>
/// Handle event if cell has lost focus.
/// </summary>
public override void OnLostFocus()
{
if (this.IsPressed)
if (this.IsOverLink)
{
this.IsPressed = false;
this.IsOverLink = false;
}
}

Expand Down