+2006-03-16 Peter Dennis Bartok <pbartok@novell.com>
+
+ * DataGrid.cs:
+ - OnMouseDown: Switch to editing mode when clicking on the cell
+ even if we're clicking on the cell that's currently
+ selected
+ - ProcessGridKey: Left/Right now wrap like MS.Net does
+ - ProcessGridKey: Tab now knows to add a new row when tab is
+ pressed in the cell of the last column of the
+ last row
+ - ProcessGridKey: Enter now adds another row if pressed in the last
+ row and selectes the new row, same column cell
+ - ProcessGridKey: Home/End navigate columns, not rows, like
+ originally implemented
+ - Broke ProcessKeyPreview code out into an extra Internal method
+ so it can be called from the edit code
+ * DataGridTextBox.cs (ProcessKeyMessage):
+ - Switched to accept Tab keypresses
+ - Added F2 handling to allow jumping to the end of the edited cell
+ - Added logic to allow moving caret left/right inside edited cell
+ and making the edited cell jump when the caret hits cell borders
+ - Tab and Enter are now passed to the datagrid after being handled
+ * TextBoxBase.cs:
+ - Removed capture code now that Control handles it
+ - set_SelectionStart now ensures caret is visible
+
2006-03-16 Jackson Harper <jackson@ximian.com>
* TrackBar.cs: Debackwards the increment/decrement for handling
DataGridCell new_cell = new DataGridCell (testinfo.Row, testinfo.Column);
- if (new_cell.Equals (current_cell) == false) {
+ if ((new_cell.Equals (current_cell) == false) || (!is_editing)) {
CancelEditing ();
SetCurrentCell (new_cell);
EditCell (current_cell);
}
break;
}
- case Keys.Tab:
+
+ case Keys.Enter: {
+ if (current_cell.RowNumber + 1 == RowsCount) {
+ DataGridCell new_cell = new DataGridCell (current_cell.RowNumber + 1, current_cell.ColumnNumber);
+
+ SetCurrentCell (new_cell);
+ EditCell (current_cell);
+ }
+ break;
+ }
+
+ case Keys.Tab: {
+ if (current_cell.ColumnNumber + 1 < CurrentTableStyle.GridColumnStyles.Count) {
+ CurrentCell = new DataGridCell (current_cell.RowNumber, current_cell.ColumnNumber + 1);
+ EditCell (current_cell);
+ } else if (current_cell.RowNumber + 1 < RowsCount) {
+ CurrentCell = new DataGridCell (current_cell.RowNumber + 1, 0);
+ EditCell (current_cell);
+ } else if ((current_cell.RowNumber + 1 == RowsCount) && (current_cell.ColumnNumber + 1 == CurrentTableStyle.GridColumnStyles.Count)) {
+ int new_row;
+ int new_col;
+
+ new_row = current_cell.RowNumber;
+ new_col = current_cell.ColumnNumber + 1;
+ if (new_col >= CurrentTableStyle.GridColumnStyles.Count) {
+ new_row++;
+ new_col = 0;
+ }
+ DataGridCell new_cell = new DataGridCell (new_row, new_col);
+
+ SetCurrentCell (new_cell);
+ EditCell (current_cell);
+ }
+ break;
+ }
+
case Keys.Right:
{
if (current_cell.ColumnNumber + 1 < CurrentTableStyle.GridColumnStyles.Count) {
CurrentCell = new DataGridCell (current_cell.RowNumber, current_cell.ColumnNumber + 1);
EditCell (current_cell);
- }
+ } else if (current_cell.RowNumber + 1 < RowsCount) {
+ CurrentCell = new DataGridCell (current_cell.RowNumber + 1, 0);
+ EditCell (current_cell);
+ }
break;
}
case Keys.Left:
if (current_cell.ColumnNumber > 0) {
CurrentCell = new DataGridCell (current_cell.RowNumber, current_cell.ColumnNumber - 1);
EditCell (current_cell);
+ } else if (current_cell.RowNumber > 0) {
+ CurrentCell = new DataGridCell (current_cell.RowNumber - 1, CurrentTableStyle.GridColumnStyles.Count - 1);
+ EditCell (current_cell);
}
break;
}
}
case Keys.Home:
{
- CurrentCell = new DataGridCell (0, current_cell.ColumnNumber);
+ CurrentCell = new DataGridCell (current_cell.RowNumber, 0);
EditCell (current_cell);
break;
}
case Keys.End:
{
- CurrentCell = new DataGridCell (RowsCount - 1, current_cell.ColumnNumber);
+ CurrentCell = new DataGridCell (current_cell.RowNumber, CurrentTableStyle.GridColumnStyles.Count - 1);
EditCell (current_cell);
break;
}
}
// Called from DataGridTextBox
- protected override bool ProcessKeyPreview (ref Message m)
- {
+ internal bool ProcessKeyPreviewInternal(ref Message m) {
Keys key = (Keys) m.WParam.ToInt32 ();
KeyEventArgs ke = new KeyEventArgs (key);
if (ProcessGridKey (ke) == true) {
return true;
}
+ return false;
+ }
+ protected override bool ProcessKeyPreview (ref Message m)
+ {
+ if (ProcessKeyPreviewInternal(ref m)) {
+ return true;
+ }
return base.ProcessKeyPreview (ref m);
}
{
isedit = true;
grid = null;
+ accepts_tab = true;
SetStyle (ControlStyles.UserPaint | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false);
SetStyle (ControlStyles.FixedHeight, true);
protected internal override bool ProcessKeyMessage (ref Message m)
{
Keys key = (Keys) m.WParam.ToInt32 ();
-
- switch (key) {
- case Keys.Return:
- grid.EndEdit (false);
- return true;
-
- case Keys.Escape:
- grid.EndEdit (true);
- return true;
-
- case Keys.Right:
- case Keys.Tab:
- case Keys.Up:
- case Keys.Down:
- case Keys.PageUp:
- case Keys.PageDown:
- case Keys.Home:
- case Keys.End:
- grid.EndEdit (false);
- break;
-
- default:
- break;
- }
-
- isedit = false;
- return base.ProcessKeyMessage (ref m);
+
+ // If we decide DataGrid needs to process we call grid.ProcessKeyPreviewInternal and return true
+ // If we want TextBox to handle the key , we return false;
+
+ // We only care about KEYDOWN messages
+ if (m.Msg != (int)Msg.WM_KEYDOWN) {
+ return false;
+ }
+
+ // Anything with control key pressed is for DataGrid
+ if ((Control.ModifierKeys & Keys.Control) != 0) {
+ return grid.ProcessKeyPreviewInternal(ref m);
+ }
+
+ if (isedit) {
+ switch (key) {
+ case Keys.F2: {
+ this.SelectionStart = this.Text.Length;
+ this.SelectionLength = 0;
+ return true;
+ }
+
+ case Keys.Up:
+ case Keys.Down:
+ case Keys.PageDown:
+ case Keys.PageUp: {
+ isedit = false;
+ grid.EndEdit(false);
+ grid.ProcessKeyPreviewInternal(ref m);
+ return true;
+ }
+
+ case Keys.Escape: {
+ isedit = false;
+ grid.EndEdit (true);
+ return true;
+ }
+
+ case Keys.Enter: {
+ isedit = false;
+ grid.EndEdit (false);
+ grid.ProcessKeyPreviewInternal(ref m);
+ return true;
+ }
+
+ case Keys.Left: {
+ if (base.SelectionStart == 0) {
+ isedit = false;
+ grid.EndEdit (false);
+ grid.ProcessKeyPreviewInternal(ref m);
+ return true;
+ }
+ return false;
+ }
+
+ case Keys.Right: {
+ // Arrow keys go right until we hit the end of the text
+ if ((base.SelectionStart + base.SelectionLength) == base.Text.Length) {
+ isedit = false;
+ grid.EndEdit (false);
+ grid.ProcessKeyPreviewInternal(ref m);
+ return true;
+ }
+ return false;
+ }
+
+ case Keys.Tab: {
+ isedit = false;
+ grid.EndEdit(false);
+ grid.ProcessKeyPreviewInternal(ref m);
+ return true;
+ }
+
+ default: {
+ return base.ProcessKeyMessage(ref m);
+ }
+ }
+ }
+
+ return base.ProcessKeyMessage(ref m);
}
public void SetDataGrid (DataGrid parentGrid)
document.CharIndexToLineTag(value, out line, out tag, out pos);
document.SetSelectionStart(line, pos);
+ ScrollToCaret();
}
}
interval = DateTime.Now - click_last;
document.PositionCaret(e.X + document.ViewPortX, e.Y + document.ViewPortY);
- this.Capture = true;
// Handle place caret/select word/select line behaviour
if (e.Clicks == 1) {
}
private void TextBoxBase_MouseUp(object sender, MouseEventArgs e) {
- this.Capture = false;
if (e.Button == MouseButtons.Left) {
document.PositionCaret(e.X + document.ViewPortX, e.Y + document.ViewPortY);
if (click_mode == CaretSelection.Position) {