protected void HandleParentCursorChanged(object sender, EventArgs e) { TreePath path; TreeIter row; TreeViewColumn col; GetCursor(out path, out col); if (Model.GetIter(out row, path) && col != null && CurrentButton != RIGHT_MOUSE_BUTTON) { bool shiftDown = (CurrentKeyboardModifier & ModifierType.ShiftMask) != ModifierType.None; bool ctrlDown = (CurrentKeyboardModifier & ModifierType.ControlMask) != ModifierType.None; mSelectionHook = (shiftDown) ? mSelectionHook : new CellLocation(row, col); List <CellLocation> selectedcells = new List <CellLocation>(SheetSelection.SelectedCells); int col1 = (selectedcells.Count > 0) ? Array.IndexOf(Columns, mSelectionHook.Col) : -1; if (col1 >= 0 && shiftDown) { SheetSelection.SelectRange(mSelectionHook.Row, col1, row, Array.IndexOf(Columns, col)); } else { if (SheetSelection.IsSelected(row, col) && (ctrlDown || selectedcells.Count == 1)) { SheetSelection.Unselect(row, col); } else { SheetSelection.Select(row, col, ctrlDown); } } QueueDraw(); } }
protected override bool OnKeyPressEvent(EventKey evnt) { CurrentKeyboardModifier = evnt.State; switch (evnt.Key) { case Gdk.Key.Left: case Gdk.Key.KP_Left: { List <TreeViewColumn> selectedcols = new List <TreeViewColumn>(SheetSelection.SelectedColumns); List <TreeViewColumn> visiblecols = (this as TreeView).VisibleColumns(); if (selectedcols.Count > 0) { int i = visiblecols.IndexOf(selectedcols[selectedcols.Count - 1]) - 1; if (i < 0) { return(true); } SheetSelection.Select(visiblecols[i], (evnt.State & ModifierType.ShiftMask) != 0); QueueDraw(); return(true); } List <CellLocation> selectedcells = new List <CellLocation>(SheetSelection.SelectedCells); if (selectedcells.Count <= 0) { return(true); } int j = visiblecols.IndexOf(selectedcells[selectedcells.Count - 1].Col) - 1; if (j < 0) { return(true); } if ((evnt.State & ModifierType.ShiftMask) == 0) { SheetSelection.Select(selectedcells[selectedcells.Count - 1].Row, visiblecols[j], false); QueueDraw(); return(true); } else { // not implemented yet //SelectRange(row1, col1, row2, col2); return(true); } } case Gdk.Key.Right: case Gdk.Key.KP_Right: { List <TreeViewColumn> selectedcols = new List <TreeViewColumn>(SheetSelection.SelectedColumns); List <TreeViewColumn> visiblecols = (this as TreeView).VisibleColumns(); if (selectedcols.Count > 0) { int i = visiblecols.IndexOf(selectedcols[selectedcols.Count - 1]) + 1; if (i <= 0 || i >= visiblecols.Count) { return(true); } SheetSelection.Select(visiblecols[i], (evnt.State & ModifierType.ShiftMask) != 0); QueueDraw(); return(true); } List <CellLocation> selectedcells = new List <CellLocation>(SheetSelection.SelectedCells); if (selectedcells.Count <= 0) { return(true); } int j = visiblecols.IndexOf(selectedcells[selectedcells.Count - 1].Col) + 1; if (j <= 0 || j >= visiblecols.Count) { return(true); } if ((evnt.State & ModifierType.ShiftMask) == 0) { SheetSelection.Select(selectedcells[selectedcells.Count - 1].Row, visiblecols[j], false); QueueDraw(); return(true); } else { // not implemented yet //SelectRange(row1, col1, row2, col2); return(true); } } case Gdk.Key.Up: case Gdk.Key.KP_Up: { List <CellLocation> selectedcells = new List <CellLocation>(SheetSelection.SelectedCells); if (selectedcells.Count <= 0) { return(true); } TreeIter row = selectedcells[selectedcells.Count - 1].Row; if (!Model.IterPrev(ref row)) { return(true); } if ((evnt.State & ModifierType.ShiftMask) == 0) { SheetSelection.Select(row, selectedcells[selectedcells.Count - 1].Col, false); QueueDraw(); return(true); } else { // not implemented yet //SelectRange(row1, col1, row2, col2); return(true); } } case Gdk.Key.Down: case Gdk.Key.KP_Down: { List <CellLocation> selectedcells = new List <CellLocation>(SheetSelection.SelectedCells); if (selectedcells.Count <= 0) { return(true); } TreeIter row = selectedcells[selectedcells.Count - 1].Row; if (!Model.IterNext(ref row)) { return(true); } if ((evnt.State & ModifierType.ShiftMask) == 0) { SheetSelection.Select(row, selectedcells[selectedcells.Count - 1].Col, false); QueueDraw(); return(true); } else { // not implemented yet //SelectRange(row1, col1, row2, col2); return(true); } } } // We do _not_ invoke // base.OnKeyPressEvent(evnt); // here. We want to have FULL control about what key does what. // No inherited logic from our parent class. //return base.OnKeyPressEvent(evnt); return(true); }