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 OnButtonPressEvent(EventButton evnt) { #region in case the mouse event happened in the header, let the base class treat it // We cannot write // if(evnt.Y<wy) // here, as GTK erroneously sets Y *WRONG* when a click happens in the header >:( // Instead, we use YRoot here which fortunately still has the proper correct value: an absolute screen coordinate. // We use it to check if the click was in the header. int ox, oy; GdkWindow.GetOrigin(out ox, out oy); if (evnt.YRoot < oy + HeaderHeight) { return(base.OnButtonPressEvent(evnt)); } #endregion TreePath path; TreeIter row; TreeViewColumn col; if (GetPathAtPos((int)evnt.X, (int)evnt.Y, out path, out col) && Model.GetIter(out row, path)) { if (evnt.Button == LEFT_MOUSE_BUTTON) { GrabFocus(); Selection.SelectNone(); List <CellLocation> selectedcells = new List <CellLocation>(SheetSelection.SelectedCells); if (selectedcells.Count <= 0 || (evnt.State & ModifierType.ShiftMask) == 0) { SheetSelection.Select(row, col, (evnt.State & ModifierType.ControlMask) != 0); } else { int col1 = Array.IndexOf(Columns, selectedcells[0].Col); if (col1 <= 0) { SheetSelection.Select(row, col, (evnt.State & ModifierType.ControlMask) != 0); } else { SheetSelection.SelectRange(selectedcells[0].Row, col1, row, Array.IndexOf(Columns, col)); } } QueueDraw(); return(true); } } return(true); //return base.OnButtonPressEvent(evnt); }