1
1
/*****************************************************************************
2
- *
2
+ *
3
3
* ReoGrid - .NET Spreadsheet Control
4
- *
4
+ *
5
5
* http://reogrid.net/
6
6
*
7
7
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
13
13
*
14
14
* Copyright (c) 2012-2016 Jing <lujing at unvell.com>
15
15
* Copyright (c) 2012-2016 unvell.com, all rights reserved.
16
- *
16
+ *
17
17
****************************************************************************/
18
18
19
19
#if WINFORM
@@ -263,15 +263,15 @@ public ReoGridControl()
263
263
BackColor = SystemColors . Control ,
264
264
TabStop = false ,
265
265
} ) ;
266
-
266
+
267
267
Controls . Add ( bottomPanel ) ;
268
268
269
269
#endregion // Bottom Panel
270
-
270
+
271
271
this . InitControl ( ) ;
272
272
273
273
ResumeLayout ( ) ;
274
-
274
+
275
275
//TODO: detect clipboard changes
276
276
// need detect and remove the hightlight range when content has been removed from System Clipboard
277
277
//ClipboardMonitor.Instance.ClipboardChanged += new EventHandler<ClipboardChangedEventArgs>(ClipboardMonitor_ClipboardChanged);
@@ -305,11 +305,11 @@ void canvasElements_VisibleChanged(object sender, EventArgs e)
305
305
this . currentWorksheet . UpdateViewportControllBounds ( ) ;
306
306
}
307
307
}
308
-
308
+
309
309
/// <summary>
310
310
/// Release resources used in this component.
311
311
/// </summary>
312
- /// <param name="disposing">True to release both managed and unmanaged resources;
312
+ /// <param name="disposing">True to release both managed and unmanaged resources;
313
313
/// False to release only unmanaged resources.</param>
314
314
protected override void Dispose ( bool disposing )
315
315
{
@@ -329,7 +329,7 @@ protected override void Dispose(bool disposing)
329
329
if ( builtInFullColSelectCursor != null ) builtInFullColSelectCursor . Dispose ( ) ;
330
330
if ( builtInFullRowSelectCursor != null ) builtInFullRowSelectCursor . Dispose ( ) ;
331
331
}
332
-
332
+
333
333
#endregion // Constructor
334
334
335
335
#region Adapter
@@ -437,7 +437,7 @@ public void ChangeCursor(CursorStyle cursor)
437
437
case CursorStyle . Selection : this . control . Cursor = this . control . internalCurrentCursor ; break ;
438
438
case CursorStyle . Busy : this . control . Cursor = Cursors . WaitCursor ; break ;
439
439
case CursorStyle . Hand : this . control . Cursor = Cursors . Hand ; break ;
440
- case CursorStyle . FullColumnSelect :
440
+ case CursorStyle . FullColumnSelect :
441
441
this . control . Cursor = this . control . FullColumnSelectionCursor != null ?
442
442
this . control . FullColumnSelectionCursor : this . control . builtInFullColSelectCursor ;
443
443
break ;
@@ -457,7 +457,7 @@ public void ChangeCursor(CursorStyle cursor)
457
457
case CursorStyle . Cross : this . control . Cursor = this . control . builtInCrossCursor ; break ;
458
458
}
459
459
}
460
-
460
+
461
461
public void RestoreCursor ( )
462
462
{
463
463
if ( this . oldCursor != null )
@@ -894,7 +894,7 @@ void sheetMenuItem_Click(object sender, EventArgs e)
894
894
this . CurrentWorksheet = sheet ;
895
895
}
896
896
}
897
-
897
+
898
898
private void ShowSheetTabControl ( )
899
899
{
900
900
if ( ! this . bottomPanel . Visible )
@@ -1028,46 +1028,58 @@ protected override void OnCreateControl()
1028
1028
{
1029
1029
sf = new StringFormat ( StringFormat . GenericDefault ) ;
1030
1030
}
1031
- protected override void OnKeyDown ( KeyEventArgs e )
1032
- {
1033
- var sheet = owner . currentWorksheet ;
1034
-
1035
- if ( sheet . currentEditingCell != null && Visible )
1036
- {
1037
- bool isProcessed = false ;
1038
-
1039
- // in single line text
1040
- if ( ! TextWrap && Text . IndexOf ( '\n ' ) == - 1 )
1041
- {
1042
- if ( e . KeyCode == Keys . Up )
1043
- {
1044
- e . SuppressKeyPress = true ;
1045
- sheet . EndEdit ( Text ) ;
1046
- sheet . MoveSelectionUp ( ) ;
1047
- isProcessed = true ;
1048
- }
1049
- else if ( e . KeyCode == Keys . Down )
1050
- {
1051
- e . SuppressKeyPress = true ;
1052
- sheet . EndEdit ( Text ) ;
1053
- sheet . MoveSelectionDown ( ) ;
1054
- isProcessed = true ;
1055
- }
1056
- }
1057
-
1058
- if ( ! isProcessed )
1059
- {
1060
- if ( ! Toolkit . IsKeyDown ( Win32 . VKey . VK_CONTROL ) && e . KeyCode == Keys . Enter )
1061
- {
1062
- e . SuppressKeyPress = true ;
1063
- sheet . EndEdit ( Text ) ;
1064
- sheet . MoveSelectionForward ( ) ;
1065
- }
1066
- }
1067
- }
1068
- }
1069
-
1070
- protected override bool ProcessCmdKey ( ref Message msg , System . Windows . Forms . Keys keyData )
1031
+ protected override void OnKeyDown ( KeyEventArgs e )
1032
+ {
1033
+ var sheet = owner . currentWorksheet ;
1034
+
1035
+ if ( sheet . currentEditingCell != null && Visible )
1036
+ {
1037
+ bool isProcessed = false ;
1038
+
1039
+ // in single line text
1040
+ if ( ! TextWrap && Text . IndexOf ( '\n ' ) == - 1 )
1041
+ {
1042
+ isProcessed = true ;
1043
+ if ( e . KeyCode == Keys . Up )
1044
+ {
1045
+ ProcessSelectionMoveKey ( e , sheet , ( ) => sheet . MoveSelectionUp ( ) ) ;
1046
+ }
1047
+ else if ( e . KeyCode == Keys . Down )
1048
+ {
1049
+ ProcessSelectionMoveKey ( e , sheet , ( ) => sheet . MoveSelectionDown ( ) ) ;
1050
+ }
1051
+ else if ( e . KeyCode == Keys . Left && SelectionStart == 0 )
1052
+ {
1053
+ ProcessSelectionMoveKey ( e , sheet , ( ) => sheet . MoveSelectionLeft ( ) ) ;
1054
+ }
1055
+ else if ( e . KeyCode == Keys . Right && SelectionStart == Text . Length )
1056
+ {
1057
+ ProcessSelectionMoveKey ( e , sheet , ( ) => sheet . MoveSelectionRight ( ) ) ;
1058
+ }
1059
+ else
1060
+ {
1061
+ isProcessed = false ;
1062
+ }
1063
+ }
1064
+
1065
+ if ( ! isProcessed )
1066
+ {
1067
+ if ( ! Toolkit . IsKeyDown ( Win32 . VKey . VK_CONTROL ) && e . KeyCode == Keys . Enter )
1068
+ {
1069
+ ProcessSelectionMoveKey ( e , sheet , ( ) => sheet . MoveSelectionForward ( ) ) ;
1070
+ }
1071
+ }
1072
+ }
1073
+ }
1074
+
1075
+ private void ProcessSelectionMoveKey ( KeyEventArgs e , Worksheet sheet , Action moveAction )
1076
+ {
1077
+ e . SuppressKeyPress = true ;
1078
+ sheet . EndEdit ( Text ) ;
1079
+ moveAction ( ) ;
1080
+ }
1081
+
1082
+ protected override bool ProcessCmdKey ( ref Message msg , System . Windows . Forms . Keys keyData )
1071
1083
{
1072
1084
var sheet = owner . currentWorksheet ;
1073
1085
@@ -1300,7 +1312,7 @@ protected override void WndProc(ref Message m)
1300
1312
return ;
1301
1313
}
1302
1314
else
1303
- // Chinese and Japanese IME will send this message
1315
+ // Chinese and Japanese IME will send this message
1304
1316
// before start to accept user's input
1305
1317
if ( m . Msg == ( int ) Win32 . WMessages . WM_IME_STARTCOMPOSITION )
1306
1318
{
@@ -1336,7 +1348,7 @@ protected override void OnResize(EventArgs e)
1336
1348
{
1337
1349
this . currentWorksheet . UpdateViewportControllBounds ( ) ;
1338
1350
}
1339
-
1351
+
1340
1352
base . OnResize ( e ) ;
1341
1353
1342
1354
if ( this . sheetTab . Right > this . bottomPanel . Width - 40 )
0 commit comments