Skip to content
Merged
Show file tree
Hide file tree
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
29 changes: 22 additions & 7 deletions ReoGrid/WPF/WPFControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -952,27 +952,42 @@ protected override void OnLostFocus(RoutedEventArgs e)
}
base.OnLostFocus(e);
}

protected override void OnPreviewKeyDown(KeyEventArgs e)
{
var sheet = this.Owner.CurrentWorksheet;

// in single line text
if (!TextWrap && Text.IndexOf('\n') == -1)
{
Action moveAction = null;

if (e.Key == Key.Up)
{
sheet.EndEdit(Text);
sheet.MoveSelectionUp();
e.Handled = true;
moveAction = () => sheet.MoveSelectionUp();
}
else if (e.Key == Key.Down)
{
sheet.EndEdit(Text);
sheet.MoveSelectionDown();
e.Handled = true;
}
moveAction = () => sheet.MoveSelectionDown();
}
else if (e.Key == Key.Left && SelectionStart == 0)
{
moveAction = () => sheet.MoveSelectionLeft();
}
else if (e.Key == Key.Right && SelectionStart == Text.Length)
{
moveAction = () => sheet.MoveSelectionRight();
}

if (moveAction != null)
{
sheet.EndEdit(Text);
moveAction();
e.Handled = true;
}
}
}

protected override void OnKeyDown(KeyEventArgs e)
{
var sheet = this.Owner.CurrentWorksheet;
Expand Down
120 changes: 66 additions & 54 deletions ReoGrid/WinForm/WinFormControl.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
*
*
* ReoGrid - .NET Spreadsheet Control
*
*
* http://reogrid.net/
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
Expand All @@ -13,7 +13,7 @@
*
* Copyright (c) 2012-2016 Jing <lujing at unvell.com>
* Copyright (c) 2012-2016 unvell.com, all rights reserved.
*
*
****************************************************************************/

#if WINFORM
Expand Down Expand Up @@ -263,15 +263,15 @@ public ReoGridControl()
BackColor = SystemColors.Control,
TabStop = false,
});

Controls.Add(bottomPanel);

#endregion // Bottom Panel

this.InitControl();

ResumeLayout();

//TODO: detect clipboard changes
// need detect and remove the hightlight range when content has been removed from System Clipboard
//ClipboardMonitor.Instance.ClipboardChanged += new EventHandler<ClipboardChangedEventArgs>(ClipboardMonitor_ClipboardChanged);
Expand Down Expand Up @@ -305,11 +305,11 @@ void canvasElements_VisibleChanged(object sender, EventArgs e)
this.currentWorksheet.UpdateViewportControllBounds();
}
}

/// <summary>
/// Release resources used in this component.
/// </summary>
/// <param name="disposing">True to release both managed and unmanaged resources;
/// <param name="disposing">True to release both managed and unmanaged resources;
/// False to release only unmanaged resources.</param>
protected override void Dispose(bool disposing)
{
Expand All @@ -329,7 +329,7 @@ protected override void Dispose(bool disposing)
if (builtInFullColSelectCursor != null) builtInFullColSelectCursor.Dispose();
if (builtInFullRowSelectCursor != null) builtInFullRowSelectCursor.Dispose();
}

#endregion // Constructor

#region Adapter
Expand Down Expand Up @@ -437,7 +437,7 @@ public void ChangeCursor(CursorStyle cursor)
case CursorStyle.Selection: this.control.Cursor = this.control.internalCurrentCursor; break;
case CursorStyle.Busy: this.control.Cursor = Cursors.WaitCursor; break;
case CursorStyle.Hand: this.control.Cursor = Cursors.Hand; break;
case CursorStyle.FullColumnSelect:
case CursorStyle.FullColumnSelect:
this.control.Cursor = this.control.FullColumnSelectionCursor!=null ?
this.control.FullColumnSelectionCursor : this.control.builtInFullColSelectCursor;
break;
Expand All @@ -457,7 +457,7 @@ public void ChangeCursor(CursorStyle cursor)
case CursorStyle.Cross: this.control.Cursor = this.control.builtInCrossCursor; break;
}
}

public void RestoreCursor()
{
if (this.oldCursor != null)
Expand Down Expand Up @@ -894,7 +894,7 @@ void sheetMenuItem_Click(object sender, EventArgs e)
this.CurrentWorksheet = sheet;
}
}

private void ShowSheetTabControl()
{
if (!this.bottomPanel.Visible)
Expand Down Expand Up @@ -1028,46 +1028,58 @@ protected override void OnCreateControl()
{
sf = new StringFormat(StringFormat.GenericDefault);
}
protected override void OnKeyDown(KeyEventArgs e)
{
var sheet = owner.currentWorksheet;

if (sheet.currentEditingCell != null && Visible)
{
bool isProcessed = false;

// in single line text
if (!TextWrap && Text.IndexOf('\n') == -1)
{
if (e.KeyCode == Keys.Up)
{
e.SuppressKeyPress = true;
sheet.EndEdit(Text);
sheet.MoveSelectionUp();
isProcessed = true;
}
else if (e.KeyCode == Keys.Down)
{
e.SuppressKeyPress = true;
sheet.EndEdit(Text);
sheet.MoveSelectionDown();
isProcessed = true;
}
}

if (!isProcessed)
{
if (!Toolkit.IsKeyDown(Win32.VKey.VK_CONTROL) && e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
sheet.EndEdit(Text);
sheet.MoveSelectionForward();
}
}
}
}

protected override bool ProcessCmdKey(ref Message msg, System.Windows.Forms.Keys keyData)
protected override void OnKeyDown(KeyEventArgs e)
{
var sheet = owner.currentWorksheet;

if (sheet.currentEditingCell != null && Visible)
{
bool isProcessed = false;

// in single line text
if (!TextWrap && Text.IndexOf('\n') == -1)
{
isProcessed = true;
if (e.KeyCode == Keys.Up)
{
ProcessSelectionMoveKey(e, sheet, () => sheet.MoveSelectionUp());
}
else if (e.KeyCode == Keys.Down)
{
ProcessSelectionMoveKey(e, sheet, () => sheet.MoveSelectionDown());
}
else if (e.KeyCode == Keys.Left && SelectionStart == 0)
{
ProcessSelectionMoveKey(e, sheet, () => sheet.MoveSelectionLeft());
}
else if (e.KeyCode == Keys.Right && SelectionStart == Text.Length)
{
ProcessSelectionMoveKey(e, sheet, () => sheet.MoveSelectionRight());
}
else
{
isProcessed = false;
}
}

if (!isProcessed)
{
if (!Toolkit.IsKeyDown(Win32.VKey.VK_CONTROL) && e.KeyCode == Keys.Enter)
{
ProcessSelectionMoveKey(e, sheet, () => sheet.MoveSelectionForward());
}
}
}
}

private void ProcessSelectionMoveKey(KeyEventArgs e, Worksheet sheet, Action moveAction)
{
e.SuppressKeyPress = true;
sheet.EndEdit(Text);
moveAction();
}

protected override bool ProcessCmdKey(ref Message msg, System.Windows.Forms.Keys keyData)
{
var sheet = owner.currentWorksheet;

Expand Down Expand Up @@ -1300,7 +1312,7 @@ protected override void WndProc(ref Message m)
return;
}
else
// Chinese and Japanese IME will send this message
// Chinese and Japanese IME will send this message
// before start to accept user's input
if (m.Msg == (int)Win32.WMessages.WM_IME_STARTCOMPOSITION)
{
Expand Down Expand Up @@ -1336,7 +1348,7 @@ protected override void OnResize(EventArgs e)
{
this.currentWorksheet.UpdateViewportControllBounds();
}

base.OnResize(e);

if (this.sheetTab.Right > this.bottomPanel.Width - 40)
Expand Down