185 lines
3.6 KiB
C#
185 lines
3.6 KiB
C#
![]() |
using System;
|
|||
|
using System.Diagnostics;
|
|||
|
using CPF.Drawing;
|
|||
|
using CPF.ReoGrid.Events;
|
|||
|
using CPF.ReoGrid.Interaction;
|
|||
|
|
|||
|
namespace CPF.ReoGrid.CellTypes
|
|||
|
{
|
|||
|
[Serializable]
|
|||
|
public class HyperlinkCell : CellBody
|
|||
|
{
|
|||
|
public Color ActivateColor { get; set; }
|
|||
|
|
|||
|
public Color LinkColor { get; set; }
|
|||
|
|
|||
|
public Color VisitedColor { get; set; }
|
|||
|
|
|||
|
public string LinkURL { get; set; }
|
|||
|
|
|||
|
public HyperlinkCell() : this(null, true)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public HyperlinkCell(string navigationURL) : this(navigationURL, true)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public HyperlinkCell(string navigationURL, bool autoNavigate)
|
|||
|
{
|
|||
|
this.ActivateColor = Color.Red;
|
|||
|
this.LinkColor = Color.Blue;
|
|||
|
this.VisitedColor = Color.Purple;
|
|||
|
this.LinkURL = navigationURL;
|
|||
|
this.AutoNavigate = autoNavigate;
|
|||
|
}
|
|||
|
|
|||
|
public bool IsPressed { get; set; }
|
|||
|
|
|||
|
public override bool OnStartEdit()
|
|||
|
{
|
|||
|
return !this.IsPressed;
|
|||
|
}
|
|||
|
|
|||
|
public override void OnSetup(Cell cell)
|
|||
|
{
|
|||
|
cell.Style.TextColor = this.LinkColor;
|
|||
|
cell.Style.Underline = true;
|
|||
|
bool flag = this.LinkURL != null;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
cell.Data = this.LinkURL;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
bool flag2 = cell.InnerData != null;
|
|||
|
if (flag2)
|
|||
|
{
|
|||
|
this.LinkURL = Convert.ToString(cell.InnerData);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override bool OnMouseDown(CellMouseEventArgs e)
|
|||
|
{
|
|||
|
this.IsPressed = true;
|
|||
|
e.Cell.Style.TextColor = this.ActivateColor;
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public override bool OnMouseUp(CellMouseEventArgs e)
|
|||
|
{
|
|||
|
bool isPressed = this.IsPressed;
|
|||
|
if (isPressed)
|
|||
|
{
|
|||
|
Rect bounds = this.Bounds;
|
|||
|
Point relativePosition = e.RelativePosition;
|
|||
|
bool flag = bounds.Contains(relativePosition);
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
this.PerformClick();
|
|||
|
}
|
|||
|
}
|
|||
|
this.IsPressed = false;
|
|||
|
e.Cell.Style.TextColor = this.VisitedColor;
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public override bool OnMouseEnter(CellMouseEventArgs e)
|
|||
|
{
|
|||
|
e.Worksheet.controlAdapter.ChangeSelectionCursor(CursorStyle.Hand);
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public override bool OnMouseLeave(CellMouseEventArgs e)
|
|||
|
{
|
|||
|
e.Worksheet.ControlAdapter.ChangeSelectionCursor(CursorStyle.PlatformDefault);
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public override bool OnKeyDown(KeyCode keyCode)
|
|||
|
{
|
|||
|
bool flag = keyCode == KeyCode.Space;
|
|||
|
bool result;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
this.IsPressed = true;
|
|||
|
base.Cell.Style.TextColor = this.ActivateColor;
|
|||
|
result = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
result = false;
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
public override bool OnKeyUp(KeyCode keyCode)
|
|||
|
{
|
|||
|
bool isPressed = this.IsPressed;
|
|||
|
bool result;
|
|||
|
if (isPressed)
|
|||
|
{
|
|||
|
this.IsPressed = false;
|
|||
|
this.PerformClick();
|
|||
|
base.Cell.Style.TextColor = this.VisitedColor;
|
|||
|
result = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
result = false;
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
public override void OnLostFocus()
|
|||
|
{
|
|||
|
bool isPressed = this.IsPressed;
|
|||
|
if (isPressed)
|
|||
|
{
|
|||
|
this.IsPressed = false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void PerformClick()
|
|||
|
{
|
|||
|
bool flag = this.AutoNavigate && !string.IsNullOrWhiteSpace(this.LinkURL);
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
RGUtility.OpenFileOrLink(this.LinkURL, null);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
Cell cell = base.Cell;
|
|||
|
if (cell != null)
|
|||
|
{
|
|||
|
Worksheet worksheet = cell.Worksheet;
|
|||
|
if (worksheet != null)
|
|||
|
{
|
|||
|
worksheet.NotifyExceptionHappen(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
EventHandler click = this.Click;
|
|||
|
if (click != null)
|
|||
|
{
|
|||
|
click(this, null);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override object OnSetData(object data)
|
|||
|
{
|
|||
|
this.LinkURL = Convert.ToString(data);
|
|||
|
return data;
|
|||
|
}
|
|||
|
|
|||
|
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
|||
|
public event EventHandler Click;
|
|||
|
|
|||
|
public bool AutoNavigate { get; set; }
|
|||
|
}
|
|||
|
}
|