From e3bcd7bf4803f60eb772f934f99c8008ccf01949 Mon Sep 17 00:00:00 2001
From: lamazze <54988641+lamazze@users.noreply.github.com>
Date: Fri, 20 Mar 2020 18:43:18 +0100
Subject: [PATCH 1/2] Update HyperLinkCell.cs
I've made all the modifications based on the behavior of the Latest Excel under Windows: the cursor change only when the mouse is over the text.
To achieve that:
1. I've changed the name of the property from IsPressed to IsOverLink.
2. I've removed OnStartEdit because you can still edit the cell even if the mouse is over the link.
3. I've remove the event OnMouseEnter and replaced them with OnMouseMove. OnMouseLeave is still there.
4. OnMouse mouse check if the mouse is over the text and change IsOverLink accordingly and manage the cursor
5. For each events, the default behavior is kept. Example: Even if the mouse is down over the text, you can still move outside the cell and select a range
6. In Excel, with the mouse down over the link, if you move the mouse before mouse up, the navigate process is stopped. Unfortunately, I couldn't reproduce since when the mouse is down, OnMouseMove isn't receiving any event. Not sure why. Same for OnMouseLeave, not sure it's useful.
---
ReoGrid/CellTypes/HyperLinkCell.cs | 117 ++++++++++-------------------
1 file changed, 41 insertions(+), 76 deletions(-)
diff --git a/ReoGrid/CellTypes/HyperLinkCell.cs b/ReoGrid/CellTypes/HyperLinkCell.cs
index e51bc546..8ae37f55 100644
--- a/ReoGrid/CellTypes/HyperLinkCell.cs
+++ b/ReoGrid/CellTypes/HyperLinkCell.cs
@@ -96,18 +96,9 @@ public HyperlinkCell(string navigationURL, bool autoNavigate)
}
///
- /// Determine whether or not the hyperlink is in pressed status.
+ /// Determine whether or not the mouse is over the hyperlink.
///
- public bool IsPressed { get; set; }
-
- ///
- /// Handle event when the cell of this body entered edit mode.
- ///
- /// True to allow edit; False to disallow edit.
- public override bool OnStartEdit()
- {
- return !this.IsPressed;
- }
+ public bool IsOverLink { get; set; }
///
/// Initialize cell body when set up into a cell.
@@ -137,11 +128,12 @@ public override void OnSetup(Cell cell)
/// True if event has been handled.
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);
}
///
@@ -151,85 +143,58 @@ public override bool OnMouseDown(CellMouseEventArgs e)
/// True if event has been handled.
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);
}
-
+
///
- /// 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.
///
/// Event argument of cell body mouse-enter.
/// True if event has been handled.
- public override bool OnMouseEnter(CellMouseEventArgs e)
- {
- e.Worksheet.controlAdapter.ChangeSelectionCursor(CursorStyle.Hand);
- return false;
- }
-
- ///
- /// Restore color of hyperlink from hover-status when mouse leaved from cell.
- ///
- /// Argument of mouse leaving event.
- /// True if this event has been handled; Otherwise return false.
- public override bool OnMouseLeave(CellMouseEventArgs e)
- {
- // change current cursor to hand
- e.Worksheet.ControlAdapter.ChangeSelectionCursor(CursorStyle.PlatformDefault);
- return false;
- }
-
- ///
- /// Handle keyboard down event.
- ///
- /// Virtual keys code that is converted from system platform.
- /// True if event has been handled; Otherwise return false.
- public override bool OnKeyDown(KeyCode keyCode)
+ public override bool OnMouseMove(CellMouseEventArgs e)
{
- if (keyCode == KeyCode.Space)
+ if (e.Cell.TextBounds.Contains(e.RelativePosition))
{
- 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);
+ }
+
///
- /// Handle keyboard up event.
+ /// Restore color of hyperlink from hover-status when mouse leaved from cell.
///
- /// Virtual keys code that is converted from system platform.
- /// True if event has been handled; Otherwise return false;
- public override bool OnKeyUp(KeyCode keyCode)
+ /// Argument of mouse leaving event.
+ /// True if this event has been handled; Otherwise return false.
+ 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);
}
///
@@ -237,9 +202,9 @@ public override bool OnKeyUp(KeyCode keyCode)
///
public override void OnLostFocus()
{
- if (this.IsPressed)
+ if (this.IsOverLink)
{
- this.IsPressed = false;
+ this.IsOverLink = false;
}
}
From d75d96bbb417b4a185642d797e1e9ad43c24c12a Mon Sep 17 00:00:00 2001
From: Jingwood
Date: Sun, 22 Mar 2020 10:45:57 +0900
Subject: [PATCH 2/2] some fixes
---
ReoGrid/CellTypes/HyperLinkCell.cs | 23 +++--------------------
1 file changed, 3 insertions(+), 20 deletions(-)
diff --git a/ReoGrid/CellTypes/HyperLinkCell.cs b/ReoGrid/CellTypes/HyperLinkCell.cs
index 8ae37f55..da11a814 100644
--- a/ReoGrid/CellTypes/HyperLinkCell.cs
+++ b/ReoGrid/CellTypes/HyperLinkCell.cs
@@ -62,30 +62,13 @@ public class HyperlinkCell : CellBody
///
public string LinkURL { get; set; }
- ///
- /// Create hyperlink cell body instance.
- ///
- public HyperlinkCell()
- : this(null, true)
- {
- }
-
- ///
- /// Create instane of hyperlink cell body with specified navigation url and AutoNavigate property.
- ///
- /// Navigation url redirected to when hyperlink clicked. (Default is emtpy)
- public HyperlinkCell(string navigationURL)
- : this(navigationURL, true)
- {
- }
-
///
/// Create instane of hyperlink cell body with specified navigation url and AutoNavigate property.
///
/// Navigation url redirected to when hyperlink clicked. (Default is emtpy)
/// Determine whether or not redirect to specified url
/// when hyperlink clicked automatically. (Default is true)
- public HyperlinkCell(string navigationURL, bool autoNavigate)
+ public HyperlinkCell(string navigationURL = null, bool autoNavigate = true)
{
this.ActivateColor = SolidColor.Red;
this.LinkColor = SolidColor.Blue;
@@ -161,7 +144,7 @@ public override bool OnMouseUp(CellMouseEventArgs e)
/// True if event has been handled.
public override bool OnMouseMove(CellMouseEventArgs e)
{
- if (e.Cell.TextBounds.Contains(e.RelativePosition))
+ if (e.Cell.TextBounds.Contains(e.AbsolutePosition))
{
if (!this.IsOverLink)
{
@@ -213,7 +196,7 @@ public override void OnLostFocus()
///
public void PerformClick()
{
- if (AutoNavigate && LinkURL != null)
+ if (AutoNavigate && !string.IsNullOrEmpty(LinkURL))
{
try
{