Beispiel #1
0
 /// <summary>
 /// Handles the mouse button being released over a column header.
 /// </summary>
 /// <param name="state">The thread initialization parameter.</param>
 protected override void OnMouseUp(MouseButtonEventArgs e)
 {
     // This resets the state of the mouse for the next operation.
     this.mouseState = MouseState.ButtonUp;
 }
Beispiel #2
0
        /// <summary>
        /// Handles the mouse button being pressed.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
        {
            // This state variable will control how the 'Mouse Move' and 'Mouse Up' event handlers interpret the user action.  The
            // 'selectedColumn' field is used as the starting point for any drag-and-drop type of operation.
            this.mouseState = MouseState.ButtonDown;

            // Evaluate the state of the keyboard.  Key combinations involving the shift and control keys will alter the areas that
            // are selected.
            bool isShiftKeyPressed   = ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift);
            bool isControlKeyPressed = ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control);

            // The mouse selected with the mouse button is used as an anchor point unless the shift key is pressed.  The anchor
            // point allows for ranges of columns to be selected.  Everything between the anchor and the currently selected column
            // will be selected when the shift key is down.  This is modeled after the Excel extended range selection keys.
            Point mouseDownLocation = e.GetPosition(this);

            // Do not clear the select cells in the Report Grid if the right mouse button is pressed.
            if (e.RightButton != MouseButtonState.Pressed)
            {
                //Since the user is selecting a cell, it will invalidate any row selection that there may be.
                foreach (List <ReportRow> block in this.ReportGrid.SelectedRowBlocks)
                {
                    foreach (ReportRow row in block)
                    {
                        foreach (ReportCell cell in row.Cells)
                        {
                            cell.IsSelected = false;
                        }
                    }
                }
                this.ReportGrid.SelectedRowBlocks.Clear();
                this.ReportGrid.SelectedRowHeaderBlocks.Clear();
            }


            if (!isShiftKeyPressed)
            {
                IInputElement    iInputElement    = this.InputHitTest(mouseDownLocation);
                DependencyObject dependencyObject = iInputElement as DependencyObject;
                while (dependencyObject != null)
                {
                    ReportCell reportCell = DynamicReport.GetCell(dependencyObject);
                    if (reportCell != null)
                    {
                        Keyboard.Focus(dependencyObject as IInputElement);
                        currentSelectedCell = reportCell;
                        break;
                    }
                    dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
                }
                this.anchorPoint = mouseDownLocation;
            }

            // The shift and control key extend the selection operation in the same way as Microsoft Excel.
            if (isShiftKeyPressed || isControlKeyPressed)
            {
                // When the shift key is pressed during column selection, every column between the last column selected
                // and the current column is selected.
                if (isShiftKeyPressed)
                {
                    // This is an ordered rectangle that encompasses all the selected cells.
                    Rect selectedRectangle = GetSelectionRectangle(mouseDownLocation);
                    SetSelectedRectangle(selectedRectangle);
                }

                // When the control key is pressed a single column is added to the range of columns selected.
                if (isControlKeyPressed)
                {
                    // A point marks the range when the control key is pressed.  This is almost identical to pressing the mouse
                    // button except the previous ranges are not cleared.  This is part of the extended selection algorithm that is
                    // modeled after Excel.
                    Rect selectedRange = new Rect(mouseDownLocation, new Size(0, 0));

                    // This removes any previous instance of this column in the selection.
                    foreach (Rect existingRange in this.selectedRanges)
                    {
                        if (selectedRange == existingRange)
                        {
                            this.selectedRanges.Remove(existingRange);
                            break;
                        }
                    }

                    // The new range becomes the starting point for any further extended selection operations.
                    this.selectedRanges.Add(selectedRange);
                }

                // This instructs the event handlers how the mouse movement is to be interpreted.
                this.mouseState = MouseState.Selecting;
            }
            else
            {
                // Evaluate if we need to be able to determine the when we right click within the currently selected range then do not clear the selectedRanges.
                if (!((e.RightButton == MouseButtonState.Pressed) && (CurrentSelectedCell != null) && (CurrentSelectedCell.IsSelected)))                 //MIGHT try this --> if (reportCell.Rect.IntersectsWith(selectedRange))
                {
                    // Clear the selected ranges as we do not have a right mouse button pressed with the currently Selected ranges.

                    // A simple selection that doesn't involve the modifier keys will clear out any previously selected ranges.
                    this.selectedRanges.Clear();
                    // The column is added at the start of a new range of selected columns.
                    this.selectedRanges.Add(new Rect(mouseDownLocation, new Size(0, 0)));
                }
            }


            // Evaluate if we need to be able to determine the when we right click within the currently selected range then do not clear the selectedRanges.
            if (!((e.RightButton == MouseButtonState.Pressed) && (CurrentSelectedCell != null) && (CurrentSelectedCell.IsSelected)))             //MIGHT try this --> if (reportCell.Rect.IntersectsWith(selectedRange))
            {
                // This will select all the columns in the selected ranges of columns and remove the selection from all the rest of the cells.
                SelectCells();
            }
        }