Пример #1
0
        internal virtual void OnMouseMove(MouseEventArgs e)
        {
            if (e.Y < RowHeight)
            {
                ColumnController <T> currentColumn = GetColumnAt(e.X);
                if (currentColumn != null)
                {
                    if (currentColumn != SelectedColumn)
                    {
                        UnselectAll();
                        SelectedColumn = currentColumn;
                    }
                    SelectedColumn.OnMouseMove(e);
                    this.OnInvalidate();
                    return;
                }
            }

            SelectedRow = GetRowAt(e.Y);
            CellController <T> currentCell = GetCellAt(e.X, SelectedRow);

            if (currentCell != SelectedCell)
            {
                UnselectAll();
                SelectedCell = currentCell;
            }

            if (SelectedCell != null)
            {
                SelectedCell.OnMouseMove(e);
                this.OnInvalidate();
            }
        }
Пример #2
0
 private void clearSelectedCell()
 {
     if (SelectedCell != null)
     {
         SelectedCell.DeselectCell();
         SelectedCell = null;
     }
 }
Пример #3
0
        private void UnHighlightNote()
        {
            if (PreviousSelectedNote == null || (SelectedCell.Column() == PreviousSelectedNote.Column && SelectedCell.Row() == PreviousSelectedNote.Row))
            {
                return;
            }

            measureGrid.Children.Remove(PreviousSelectedNote.Canvas);
            PreviousSelectedNote = measure.UnHighlightNote(PreviousSelectedNote.Column, PreviousSelectedNote.Row);
            measureGrid.AddInGrid(PreviousSelectedNote);
        }
Пример #4
0
        public void IsSelected_ShouldReturnTrueForReplaced()
        {
            //Arrange
            SelectedCell subject = new SelectedCell(null);

            //Act
            Bool actual = subject.IsSelected();

            //Assert
            ((bool)actual).Should().BeTrue();
        }
Пример #5
0
        private void AddNote()
        {
            Note note = measure.Add(SelectedCell.Column(), SelectedCell.Row());

            if (note != null)
            {
                SelectedNote        = note;
                MostRecentAddedNote = note;
            }

            AddNoteToXAML(note);
        }
Пример #6
0
        public void Value_ShouldReturnValueOfOrigin()
        {
            //Arrange
            Glyph        origin  = new Glyph('?');
            SelectedCell subject = new SelectedCell(origin);

            //Act
            string actual = subject.Value();

            //Assert
            actual.Should().Be("?");
        }
Пример #7
0
 internal virtual void OnMouseDown(MouseEventArgs e)
 {
     if (SelectedCell != null)
     {
         SelectedCell.OnMouseDown(e);
         this.OnInvalidate();
     }
     else if (SelectedColumn != null)
     {
         SelectedColumn.OnMouseDown(e);
         this.OnInvalidate();
     }
 }
Пример #8
0
        private void GridCellMouseDoubleClickHandler(GridCell targetCell, GridCell.GridCellInteractionEventArgs e)
        {
            if (SelectedCell == targetCell && SelectedCell.IsEditable)
            {
                return;
            }
            UnpointCell();

            SelectedCell.UncheckCell();
            SelectedCell            = targetCell;
            SelectedCell.IsEditable = true;

            UpdateBinding();
        }
Пример #9
0
 internal virtual void OnMouseUp(MouseEventArgs e)
 {
     if (SelectedRow != null && SelectedCell != null)
     {
         SelectedCell.OnMouseUp(e);
         this.OnInvalidate();
         this.OnCellClick(SelectedRow.Model, SelectedCell.View.Column);
     }
     else if (SelectedColumn != null)
     {
         SelectedColumn.OnMouseUp(e);
         this.OnInvalidate();
     }
 }
Пример #10
0
        private void OnMeasureGridRightClicked(MouseButtonEventArgs e)
        {
            UpdateSelectedColumnAndRow(e.Source as FrameworkElement);

            Note note = measure.GetNote(SelectedCell.Column(), SelectedCell.Row());

            if (note != null)
            {
                UnHighlightNote();

                measure.Delete(note.Column, note.Row);
                measureGrid.Children.Remove(note.Canvas);

                SelectedNote         = null;
                PreviousSelectedNote = null;
            }
        }
Пример #11
0
        public bool TrySelect(GridCoordinates targetCell)
        {
            if (!watchedCells.ContainsKey(targetCell))
            {
                return(false);
            }
            if (targetCell.Equals(SelectedCell.CellPosition))
            {
                return(false);
            }

            UnpointCell();

            SelectedCell.UncheckCell();
            SelectedCell            = watchedCells[targetCell];
            SelectedCell.IsSelected = true;

            UpdateBinding();
            return(true);
        }
Пример #12
0
        public bool TryMoveSelection(Direction dir)
        {
            if (SelectedCell == null)
            {
                return(false);
            }

            if (!CoordsInDirectionExist(dir, out GridCoordinates targetCoordinates))
            {
                return(false);
            }

            SelectedCell.UncheckCell();
            SelectedCell            = watchedCells[targetCoordinates];
            SelectedCell.IsSelected = true;

            UnpointCell();
            UpdateBinding();

            return(true);
        }
Пример #13
0
        private void UpdateHighlightedNote()
        {
            if (measure.GetNote(SelectedCell.Column(), SelectedCell.Row()) == null)
            {
                HighlightNote(MostRecentAddedNote);
            }

            else
            {
                Note selectedNote = measure.GetNote(SelectedCell.Column(), SelectedCell.Row());

                if (selectedNote == null)
                {
                    return;
                }

                HighlightNote(selectedNote);
            }

            UnHighlightNote();
        }
Пример #14
0
        private void selectCell(CellViewModel cellVM)
        {
            // Deselect old cell first
            if (SelectedCell != null && SelectedCell != cellVM)
            {
                SelectedCell.DeselectCell();
            }
            // Don't reselect the same cell. Treat it as a deselect instead and bail out.
            if (SelectedCell == cellVM)
            {
                clearSelectedCell();
                return;
            }

            // Note the select and signal the cell's viewmodel that it make the cell/peg look selected.
            SelectedCell = cellVM;
            var holdPosition = PegHoldPosition.position;

            cellVM.SelectCell(holdPosition);

            // Audio feedback of select
            audioManager.PlaySelect();
        }
Пример #15
0
        private void UpdateSelectedColumnAndRow(FrameworkElement source)
        {
            if (source.Parent is Grid)
            {
                if (source.GetType() == typeof(Canvas))
                {
                    SelectedCell = new Dictionary <string, int> {
                        { "column", ((source as Canvas).Tag as Cell).column }, { "row", ((source as Canvas).Tag as Cell).row }
                    };
                }
                else
                {
                    SelectedCell = new Dictionary <string, int> {
                        { "column", (int)source.GetValue(Grid.ColumnProperty) }, { "row", (int)source.GetValue(Grid.RowProperty) }
                    };
                }


                Note note = measure.GetNote(SelectedCell.Column(), SelectedCell.Row());

                if (note != null)
                {
                    SelectedNote = note;
                }
            }

            else
            {
                //testing purposes
                int col = (int)source.GetValue(Grid.ColumnProperty);
                int row = (int)source.GetValue(Grid.RowProperty);


                UpdateSelectedColumnAndRow(source.Parent as FrameworkElement);
            }
        }
Пример #16
0
        /// <summary> Add a row. If insertatrow=-1, add to end. Else inserted before index</summary>
        public void AddRow(GLDataGridViewRow row, int insertatrow = -1)
        {
            System.Diagnostics.Debug.Assert(row.Parent == this && row.HeaderStyle.Parent != null); // ensure created by us
            row.HeaderStyle.Changed += (e1) => { ContentInvalidateLayout(); };                     // header style changed, need a complete refresh
            row.AutoSizeGeneration   = 0;
            row.Changed             += (e1) =>
            {
                contentpanel.RowChanged(row.Index); // inform CP
                UpdateScrollBar();                  // update scroll bar
            };

            row.SelectionChanged += (rw, cellno) =>
            {
                //System.Diagnostics.Debug.WriteLine($"Selection changed on {rw.Index} {cellno}");

                if (cellno == -1)                           // if whole row select
                {
                    if (rw.Selected)                        // turning on
                    {
                        if (!AllowUserToSelectMultipleRows) // if not allowed multirow, clear all
                        {
                            ClearSelection();
                        }

                        if (!selectedcells.ContainsKey(rw.Index))
                        {
                            selectedcells[rw.Index] = new HashSet <int>();
                        }

                        foreach (var c in rw.Cells)
                        {
                            selectedcells[rw.Index].Add(c.Index);
                        }

                        SelectedRow?.Invoke(rw, true);
                    }
                    else
                    {   // turning off
                        foreach (var c in rw.Cells)
                        {
                            selectedcells[rw.Index].Remove(c.Index);
                        }

                        if (selectedcells[rw.Index].Count == 0)
                        {
                            selectedcells.Remove(rw.Index);
                        }

                        SelectedRow?.Invoke(rw, false);
                    }
                }
                else if (rows[rw.Index].Cells[cellno].Selected)     // individual cell turning on
                {
                    if (!selectedcells.ContainsKey(rw.Index))
                    {
                        selectedcells[rw.Index] = new HashSet <int>();
                    }
                    selectedcells[rw.Index].Add(cellno);

                    SelectedCell?.Invoke(rows[rw.Index].Cells[cellno], true);
                }
                else
                {
                    selectedcells[rw.Index].Remove(cellno);     // or turning off

                    if (selectedcells[rw.Index].Count == 0)
                    {
                        selectedcells.Remove(rw.Index);
                    }

                    SelectedCell?.Invoke(rows[rw.Index].Cells[cellno], false);
                }

                contentpanel.RowChanged(row.Index);     // inform CP
            };

            if (insertatrow == -1)
            {
                row.SetRowNo(rows.Count, (rows.Count & 1) != 0 ? DefaultAltRowCellStyle : DefaultCellStyle);
                rows.Add(row);
                contentpanel.AddRow(row.Index);       // see if content panel needs redrawing
            }
            else
            {
                rows.Insert(insertatrow, row);
                for (int i = insertatrow; i < rows.Count; i++)
                {
                    rows[i].SetRowNo(i, (i & 1) != 0 ? DefaultAltRowCellStyle : DefaultCellStyle);
                }
                contentpanel.InsertRow(row.Index);       // see if content panel needs redrawing
            }

            UpdateScrollBar();
        }
Пример #17
0
 private bool IsNotePresentOnSelectedCell()
 {
     return(measure.GetNote(SelectedCell.Column(), SelectedCell.Row()) != null);
 }