Пример #1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (CmdCode.Length != 0)
            {
                hash ^= CmdCode.GetHashCode();
            }
            if (Identity.Length != 0)
            {
                hash ^= Identity.GetHashCode();
            }
            if (OppositeId.Length != 0)
            {
                hash ^= OppositeId.GetHashCode();
            }
            if (ServerId != 0)
            {
                hash ^= ServerId.GetHashCode();
            }
            if (CellAddr != 0)
            {
                hash ^= CellAddr.GetHashCode();
            }
            if (LightNo.Length != 0)
            {
                hash ^= LightNo.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Пример #2
0
        static List <int> getAvailables(CellAddr cellAddr)
        {
            List <int> available = values.ToList();

            for (int i = 0; i < 9; i++)
            {
                if (currentMatrix[i, cellAddr.column] != -1)
                {
                    available.Remove(currentMatrix[i, cellAddr.column]);
                }

                if (currentMatrix[cellAddr.row, i] != -1)
                {
                    available.Remove(currentMatrix[cellAddr.row, i]);
                }
            }

            int rowStart    = (cellAddr.row / 3) * 3;
            int columnStart = (cellAddr.column / 3) * 3;

            for (int i = rowStart; i < (rowStart + 3); i++)
            {
                for (int j = columnStart; j < (columnStart + 3); j++)
                {
                    if (currentMatrix[i, j] != -1)
                    {
                        available.Remove(currentMatrix[i, j]);
                    }
                }
            }

            return(available);
        }
Пример #3
0
        // Paste from the Clipboard.  Need to distinguish:
        // 1. Paste from Corecalc formula Copy: preserve sharing
        // 2. Paste from Corecalc cell Cut: adjust referring cells and this, if formula
        // 3. Paste from text (e.g. from Excel), parse to new cell

        public void Paste()
        {
            if (Clipboard.ContainsData(ClipboardCell.COPIED_CELL))
            {
                // Copy Corecalc cell
                ClipboardCell cc = (ClipboardCell)Clipboard.GetData(ClipboardCell.COPIED_CELL);
                Console.WriteLine("Pasting copied cell " + Clipboard.GetText());
                Cell cell = sheet.workbook[cc.FromSheet][cc.FromCellAddr];
                int  col, row, cols, rows;
                GetSelectedColsRows(out col, out row, out cols, out rows);
                sheet.PasteCell(cell, col, row, cols, rows);
                RecalculateAndShow();
            }
            else if (Clipboard.ContainsData(ClipboardCell.CUT_CELL))
            {
                // Move Corecalc cell
                Console.WriteLine("Pasting moved cell not implemented.");
            }
            else if (Clipboard.ContainsText())
            {
                // Insert text (from external source)
                CellAddr ca   = new CellAddr(dgv.CurrentCellAddress);
                String   text = Clipboard.GetText();
                Console.WriteLine("Pasting text " + text);
                SetCell(ca.col, ca.row, text);
            }
        }
Пример #4
0
        public void Delete()
        {
            CellAddr ca = new CellAddr(dgv.CurrentCellAddress);

            sheet.SetCell(null, ca.col, ca.row);
            RecalculateAndShow();
        }
Пример #5
0
        // Insert cell, which must be Formula, as array formula
        // in area ((ulCol,ulRow), (lrCol, lrRow))
        public void SetArrayFormula(Cell cell, int col, int row, CellAddr ulCa, CellAddr lrCa)
        {
            Formula formula = cell as Formula;

            if (cell == null)
            {
                throw new Exception("Invalid array formula");
            }
            else
            {
                CachedArrayFormula caf = new CachedArrayFormula(formula, this, col, row, ulCa, lrCa);
                // Increase support sets of cells referred by formula
                formula.AddToSupportSets(this, col, row, 1, 1);
                Interval displayCols = new Interval(ulCa.col, lrCa.col),
                         displayRows = new Interval(ulCa.row, lrCa.row);
                // The underlying formula supports (only) the ArrayFormula cells in display range
                formula.ResetSupportSet();
                formula.AddSupport(this, col, row, this, displayCols, displayRows);
                int cols = lrCa.col - ulCa.col + 1, rows = lrCa.row - ulCa.row + 1;
                for (int c = 0; c < cols; c++)
                {
                    for (int r = 0; r < rows; r++)
                    {
                        this[ulCa.col + c, ulCa.row + r] = new ArrayFormula(caf, c, r);
                    }
                }
            }
        }
Пример #6
0
        // Evaluate cell ref by evaluating the cell referred to

        public override Value Eval(Sheet sheet, int col, int row)
        {
            CellAddr ca   = raref.Addr(col, row);
            Cell     cell = (this.sheet ?? sheet)[ca];

            return(cell == null ? null : cell.Eval(sheet, ca.col, ca.row));
        }
Пример #7
0
		public ArrayExplicit(CellAddr ulCa, CellAddr lrCa, Value[,] values) {
			this.ulCa = ulCa;
			this.lrCa = lrCa;
			this.values = values;
			this.cols = lrCa.col - ulCa.col + 1;
			this.rows = lrCa.row - ulCa.row + 1;
		}
Пример #8
0
        // Attempt to parse s as cell contents, and set selected cell(s)

        private void SetCell(int col, int row, String text, DataGridViewCellValidatingEventArgs arg = null)
        {
            Cell         cell            = Cell.Parse(text, sheet.workbook, col, row);
            ArrayFormula oldArrayFormula = sheet[col, row] as ArrayFormula;

            gui.SetCyclicError(null);
            if (cell == null)
            {
                if (text.TrimStart(' ').StartsWith("="))                   // Ill-formed formula, cancel edit
                {
                    if (arg != null)
                    {
                        ErrorMessage("Bad formula");
                        arg.Cancel = true;
                    }
                    return;
                }
                else if (!String.IsNullOrWhiteSpace(text))                 // Assume a quote expression
                {
                    cell = Cell.Parse("'" + text, sheet.workbook, col, row);
                }
            }
            DataGridViewSelectedCellCollection dgvscc = dgv.SelectedCells;

            if (dgvscc.Count > 1 && cell is Formula)               // Array formula
            {
                int ulCol = col, ulRow = row, lrCol = col, lrRow = row;
                foreach (DataGridViewCell dgvc in dgvscc)
                {
                    ulCol = Math.Min(ulCol, dgvc.ColumnIndex);
                    ulRow = Math.Min(ulRow, dgvc.RowIndex);
                    lrCol = Math.Max(lrCol, dgvc.ColumnIndex);
                    lrRow = Math.Max(lrRow, dgvc.RowIndex);
                }
                CellAddr ulCa = new CellAddr(ulCol, ulRow),
                         lrCa = new CellAddr(lrCol, lrRow);
                if (oldArrayFormula != null && arg != null &&
                    !(oldArrayFormula.caf.ulCa.Equals(ulCa) &&
                      oldArrayFormula.caf.lrCa.Equals(lrCa)))
                {
                    ErrorMessage("Cannot edit part of array formula");
                    arg.Cancel = true;
                    return;
                }
                sheet.SetArrayFormula(cell, col, row, ulCa, lrCa);
            }
            else               // One-cell formula, or constant, or null (parse error)
            {
                if (oldArrayFormula != null && arg != null)
                {
                    ErrorMessage("Cannot edit part of array formula");
                    arg.Cancel = true;
                    return;
                }
                sheet.SetCell(cell, col, row);
            }
            RecalculateAndShow();
            gui.SetCyclicError("Cyclic dependency");
        }
Пример #9
0
 public ArrayExplicit(CellAddr ulCa, CellAddr lrCa, Value[,] values)
 {
     this.ulCa   = ulCa;
     this.lrCa   = lrCa;
     this.values = values;
     this.cols   = lrCa.col - ulCa.col + 1;
     this.rows   = lrCa.row - ulCa.row + 1;
 }
Пример #10
0
 private ArrayView(CellAddr ulCa, CellAddr lrCa, Sheet sheet)
 {
     this.sheet = sheet;
     this.ulCa  = ulCa;
     this.lrCa  = lrCa;
     this.cols  = lrCa.col - ulCa.col + 1;
     this.rows  = lrCa.row - ulCa.row + 1;
 }
Пример #11
0
        // Copy sheet's currently active cell to Clipboard, also in text format

        public void Copy()
        {
            CellAddr   ca   = new CellAddr(dgv.CurrentCellAddress);
            DataObject data = new DataObject();

            data.SetData(DataFormats.Text, sheet[ca].Show(ca.col, ca.row, sheet.workbook.format));
            data.SetData(ClipboardCell.COPIED_CELL, new ClipboardCell(sheet.Name, ca));
            Clipboard.Clear();
            Clipboard.SetDataObject(data, false);
        }
Пример #12
0
		public override Value View(CellAddr ulCa, CellAddr lrCa) {
			int cols = Cols, rows = Rows, col0 = ulCa.col, row0 = ulCa.row;
			Value[,] vals = new Value[cols, rows];
			for (int c = 0; c < cols; c++) {
				for (int r = 0; r < rows; r++) {
					vals[c, r] = NumberValue.Make(matrix[row0 + r, col0 + c]);
				}
			}
			return new ArrayExplicit(vals);
		}
Пример #13
0
 private void CellToCellArrow(Graphics g, Pen pen, CellAddr ca1, CellAddr ca2)
 {
     if (dgv[ca1.col, ca1.row].Displayed || dgv[ca2.col, ca2.row].Displayed)
     {
         // Sadly, dgv.GetCellDisplayRectangle returns Empty outside visible area
         int x1 = (colOffset[ca1.col] + colOffset[ca1.col + 1]) / 2,
             y1 = (rowOffset[ca1.row] + rowOffset[ca1.row + 1]) / 2,
             x2 = (colOffset[ca2.col] + colOffset[ca2.col + 1]) / 2,
             y2 = (rowOffset[ca2.row] + rowOffset[ca2.row + 1]) / 2;
         g.DrawLine(pen, x1, y1, x2, y2);
     }
 }
Пример #14
0
        bool iterate()
        {
            iterateCount++;

            CellAddr cellAddr = getNextCell();

            if (cellAddr == null)
            {
                return(true);
            }

            List <int> availables = getAvailables(cellAddr);

            foreach (int available in availables)
            {
                currentMatrix[cellAddr.row, cellAddr.column] = available;
                Debug.Write("\n" + cellAddr.row + "," + cellAddr.column + ":" + available);

                formMatrixUpdater(this, new MatrixChangedEventArgs()
                {
                    textBox = formMatrix[cellAddr.row, cellAddr.column],
                    value   = available.ToString()
                });

                progressBarUpdater(this, new ProgressChangedEventArgs()
                {
                    progressBar = progressBar,
                    progress    = currentProgress
                });

                if (iterate())
                {
                    return(true);
                }

                currentMatrix[cellAddr.row, cellAddr.column] = -1;

                formMatrixUpdater(this, new MatrixChangedEventArgs()
                {
                    textBox = formMatrix[cellAddr.row, cellAddr.column],
                    value   = string.Empty
                });

                progressBarUpdater(this, new ProgressChangedEventArgs()
                {
                    progressBar = progressBar,
                    progress    = currentProgress
                });
            }

            return(false);
        }
Пример #15
0
        public override Value View(CellAddr ulCa, CellAddr lrCa)
        {
            int cols = Cols, rows = Rows, col0 = ulCa.col, row0 = ulCa.row;

            Value[,] vals = new Value[cols, rows];
            for (int c = 0; c < cols; c++)
            {
                for (int r = 0; r < rows; r++)
                {
                    vals[c, r] = NumberValue.Make(matrix[row0 + r, col0 + c]);
                }
            }
            return(new ArrayExplicit(vals));
        }
Пример #16
0
        public ArrayView MakeArrayView(Sheet sheet, int col, int row)
        {
            CellAddr  ulCa = ul.Addr(col, row), lrCa = lr.Addr(col, row);
            ArrayView view = ArrayView.Make(ulCa, lrCa, this.sheet ?? sheet);

            // Forcing the evaluation of all cells in an array view value.
            // TODO: Doing this repeatedly, as in ManyDependents.xml, is costly
            for (int c = 0; c < view.Cols; c++)
            {
                for (int r = 0; r < view.Rows; r++)
                {
                    // Value ignore = view[c, r];
                }
            }
            return(view);
        }
Пример #17
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (CellAddr != 0)
            {
                hash ^= CellAddr.GetHashCode();
            }
            if (Status.Length != 0)
            {
                hash ^= Status.GetHashCode();
            }
            if (LightPw != 0)
            {
                hash ^= LightPw.GetHashCode();
            }
            if (LightLu != 0)
            {
                hash ^= LightLu.GetHashCode();
            }
            if (LightLi != 0)
            {
                hash ^= LightLi.GetHashCode();
            }
            if (LightBu != 0)
            {
                hash ^= LightBu.GetHashCode();
            }
            if (LightBt != 0)
            {
                hash ^= LightBt.GetHashCode();
            }
            if (LightUu != 0)
            {
                hash ^= LightUu.GetHashCode();
            }
            if (LightUi != 0)
            {
                hash ^= LightUi.GetHashCode();
            }
            hash ^= lightBgus_.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Пример #18
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (CellAddr != 0)
            {
                hash ^= CellAddr.GetHashCode();
            }
            if (LightNo.Length != 0)
            {
                hash ^= LightNo.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Пример #19
0
		private bool supportAdded, supportRemoved; // Referred cells' support sets up to date

		// Invariant: Every cell within the display area sheet[ulCa, lrCa] is an 
		// ArrayFormula whose CachedArrayFormula instance is this one.

		public CachedArrayFormula(Formula formula,
								  Sheet sheet,
								  int formulaCol,
								  int formulaRow,
								  CellAddr ulCa,
								  CellAddr lrCa) {
			if (formula == null) {
				throw new Exception("CachedArrayFormula arguments");
			}
			else {
				this.formula = formula;
				this._sheet = sheet;
				this.formulaCol = formulaCol;
				this.formulaRow = formulaRow;
				this.ulCa = ulCa;
				this.lrCa = lrCa;
				this.supportAdded = this.supportRemoved = false;
			}
		}
Пример #20
0
 // Painting arrows to dependents and precedents of cell ca
 private void DrawDependents(Graphics g, Pen pen, int depth, CellAddr ca, HashSet <CellAddr> done)
 {
     if (depth > 0 && !done.Contains(ca))
     {
         done.Add(ca);
         Cell cell = sheet[ca];
         if (cell != null)
         {
             cell.ForEachSupported(delegate(Sheet suppSheet, int suppCol, int suppRow) {
                 CellAddr dependent = new CellAddr(suppCol, suppRow);
                 if (suppSheet == sheet)
                 {
                     CellToCellArrow(g, pen, ca, dependent);
                     DrawDependents(g, pen, depth - 1, dependent, done);
                 }
             });
         }
     }
 }
Пример #21
0
 private void DrawPrecedents(Graphics g, Pen pen, int depth, CellAddr ca, HashSet <CellAddr> done)
 {
     if (depth > 0 && !done.Contains(ca))
     {
         done.Add(ca);
         Cell cell = sheet[ca];
         if (cell != null)
         {
             cell.ForEachReferred(sheet,
                                  ca.col,
                                  ca.row,
                                  delegate(FullCellAddr precedent) {
                 if (precedent.sheet == sheet)
                 {
                     CellToCellArrow(g, pen, precedent.ca, ca);
                     DrawPrecedents(g, pen, depth - 1, precedent.ca, done);
                 }
             });
         }
     }
 }
Пример #22
0
        private bool supportAdded, supportRemoved;  // Referred cells' support sets up to date

        // Invariant: Every cell within the display area sheet[ulCa, lrCa] is an
        // ArrayFormula whose CachedArrayFormula instance is this one.

        public CachedArrayFormula(Formula formula,
                                  Sheet sheet,
                                  int formulaCol,
                                  int formulaRow,
                                  CellAddr ulCa,
                                  CellAddr lrCa)
        {
            if (formula == null)
            {
                throw new Exception("CachedArrayFormula arguments");
            }
            else
            {
                this.formula      = formula;
                this._sheet       = sheet;
                this.formulaCol   = formulaCol;
                this.formulaRow   = formulaRow;
                this.ulCa         = ulCa;
                this.lrCa         = lrCa;
                this.supportAdded = this.supportRemoved = false;
            }
        }
Пример #23
0
Файл: GUI.cs Проект: Dugin13/P10
 public void Delete()
 {
     CellAddr ca = new CellAddr(dgv.CurrentCellAddress);
       sheet.SetCell(null, ca.col, ca.row);
       RecalculateAndShow();
 }
Пример #24
0
        public void ApplyToFcas(Sheet sheet, int col, int row, Action <FullCellAddr> act)
        {
            CellAddr ulCa = ul.Addr(col, row), lrCa = lr.Addr(col, row);

            ArrayView.Make(ulCa, lrCa, this.sheet ?? sheet).Apply(act);
        }
Пример #25
0
 public Cell this[CellAddr ca] {
     get { return(this[ca.col, ca.row]); }
     private set { this[ca.col, ca.row] = value; }
 }
Пример #26
0
Файл: GUI.cs Проект: Dugin13/P10
 public SheetTab(WorkbookForm gui, Sheet sheet)
     : base(sheet.Name)
 {
     this.gui = gui;
       this.sheet = sheet;
       this.Name = sheet.Name;
       this.dgv = new DataGridView();
       dgv.ShowEditingIcon = false;
       dgv.Dock = DockStyle.Fill;
       Dock = DockStyle.Fill;
       // Display formula in the current cell and computed value in other cells
       dgv.CellFormatting +=
     delegate(Object sender, DataGridViewCellFormattingEventArgs e) {
       int col = e.ColumnIndex, row = e.RowIndex;
       if (col == dgv.CurrentCellAddress.X && row == dgv.CurrentCellAddress.Y) {
     Object obj = sheet.Show(col, row);
     if (obj != null) {
       e.Value = obj;
       e.FormattingApplied = true;
     }
       } else {
     Object obj = sheet.ShowValue(col, row);
     if (obj != null) {
       e.Value = obj;
       e.FormattingApplied = true;
     }
       }
     };
       // Show current cell's address, and show formula in formula box
       dgv.CellEnter +=
     delegate(Object sender, DataGridViewCellEventArgs arg) {
       int row = arg.RowIndex, col = arg.ColumnIndex;
       dgv.TopLeftHeaderCell.Value = new CellAddr(col, row).ToString();
       gui.formulaBox.Text = (String)dgv.CurrentCell.FormattedValue;
     };
       // Check that cell's contents is well-formed after edit
       dgv.CellValidating +=
     delegate(Object sender, DataGridViewCellValidatingEventArgs arg) {
       if (dgv.IsCurrentCellInEditMode) {   // Update only if cell was edited
     int row = arg.RowIndex, col = arg.ColumnIndex;
     Object value = arg.FormattedValue;
     if (value != null)
       SetCell(col, row, value.ToString(), arg);
       }
     };
       // Experiment with painting on the data grid view
       dgv.Paint += delegate(Object sender, PaintEventArgs arg) {
     base.OnPaint(arg);
     // Update column and row offset tables for drawing arrows between cells:
     int offset = dgv.RowHeadersWidth;
     for (int col = 0; col < sheet.Cols; col++) {
       colOffset[col] = offset;
       offset += dgv.Columns[col].Width;
     }
     colOffset[sheet.Cols] = offset;
     offset = dgv.ColumnHeadersHeight;
     for (int row = 0; row < sheet.Rows; row++) {
       rowOffset[row] = offset;
       offset += dgv.Rows[row].Height;
     }
     rowOffset[sheet.Rows] = offset;
     Pen pen = new Pen(Color.Blue, 1);
     pen.EndCap = SDD2D.LineCap.ArrowAnchor;
     pen.StartCap = SDD2D.LineCap.RoundAnchor;
     if (dgv.SelectedCells.Count > 0) {
       DataGridViewCell dgvc = dgv.SelectedCells[0];
       CellAddr ca = new CellAddr(dgvc.ColumnIndex, dgvc.RowIndex);
       Graphics g = arg.Graphics;
       g.SmoothingMode = SDD2D.SmoothingMode.AntiAlias;
       int x = dgv.RowHeadersWidth, y = dgv.ColumnHeadersHeight,
       w = dgv.DisplayRectangle.Width - x, h = dgv.DisplayRectangle.Height - y;
       // Clip headers *before* the scroll translation/transform
       g.Clip = new Region(new Rectangle(x, y, w, h));
       g.Transform = new SDD2D.Matrix(1, 0, 0, 1,
     -dgv.HorizontalScrollingOffset, -dgv.VerticalScrollingOffset);
       SupportArea.IdempotentForeach = false; // Draw all arrows into a cell
       DrawDependents(g, pen, gui.dependentsDepth, ca, new HashSet<CellAddr>());
       DrawPrecedents(g, pen, gui.precedentsDepth, ca, new HashSet<CellAddr>());
     }
       };
       dgv.SelectionChanged += delegate(Object sender, EventArgs arg) {
     if (gui.dependentsDepth != 0 || gui.precedentsDepth != 0) {
       gui.dependentsDepth = gui.precedentsDepth = 0;
       Refresh();
     }
       };
       // Strange: to hold sheet, we need an extra row, but not an extra column?
       dgv.ColumnCount = sheet.Cols;
       dgv.RowCount = sheet.Rows + 1;
       // Allocate offset tables to assist drawing arrows between cells
       colOffset = new int[sheet.Cols + 1];
       rowOffset = new int[sheet.Rows + 1];
       dgv.AllowUserToAddRows = false;
       // Put labels on columns and rows, disable (meaningless) row sorting:
       for (int col = 0; col < dgv.ColumnCount; col++) {
     dgv.Columns[col].Name = CellAddr.ColumnName(col);
     dgv.Columns[col].SortMode = DataGridViewColumnSortMode.NotSortable;
       }
       for (int row = 0; row < dgv.RowCount; row++)
     dgv.Rows[row].HeaderCell.Value = (row + 1).ToString();
       if (sheet.IsFunctionSheet) {
     DataGridViewCellStyle cellStyle = new DataGridViewCellStyle();
     cellStyle.BackColor = Color.LightPink;
     dgv.ColumnHeadersDefaultCellStyle = dgv.RowHeadersDefaultCellStyle = cellStyle;
       }
       // Somewhat arbitrary extension of the width -- using
       // Graphics.MeasureString("0000", dgv.Font) would be better
       dgv.RowHeadersWidth += 20;
       Controls.Add(dgv);
 }
Пример #27
0
Файл: GUI.cs Проект: Dugin13/P10
 // Attempt to parse s as cell contents, and set selected cell(s)
 private void SetCell(int col, int row, String text, DataGridViewCellValidatingEventArgs arg = null)
 {
     Cell cell = Cell.Parse(text, sheet.workbook, col, row);
       ArrayFormula oldArrayFormula = sheet[col, row] as ArrayFormula;
       gui.SetCyclicError(null);
       if (cell == null) {
     if (text.TrimStart(' ').StartsWith("=")) {    // Ill-formed formula, cancel edit
       if (arg != null) {
     ErrorMessage("Bad formula");
     arg.Cancel = true;
       }
       return;
     } else if (!String.IsNullOrWhiteSpace(text)) // Assume a quote expression
       cell = Cell.Parse("'" + text, sheet.workbook, col, row);
       }
       DataGridViewSelectedCellCollection dgvscc = dgv.SelectedCells;
       if (dgvscc.Count > 1 && cell is Formula) { // Array formula
     int ulCol = col, ulRow = row, lrCol = col, lrRow = row;
     foreach (DataGridViewCell dgvc in dgvscc) {
       ulCol = Math.Min(ulCol, dgvc.ColumnIndex);
       ulRow = Math.Min(ulRow, dgvc.RowIndex);
       lrCol = Math.Max(lrCol, dgvc.ColumnIndex);
       lrRow = Math.Max(lrRow, dgvc.RowIndex);
     }
     CellAddr ulCa = new CellAddr(ulCol, ulRow),
          lrCa = new CellAddr(lrCol, lrRow);
     if (oldArrayFormula != null && arg != null
     && !(oldArrayFormula.caf.ulCa.Equals(ulCa)
          && oldArrayFormula.caf.lrCa.Equals(lrCa)))
     {
       ErrorMessage("Cannot edit part of array formula");
       arg.Cancel = true;
       return;
     }
     sheet.SetArrayFormula(cell, col, row, ulCa, lrCa);
       } else { // One-cell formula, or constant, or null (parse error)
     if (oldArrayFormula != null && arg != null) {
       ErrorMessage("Cannot edit part of array formula");
       arg.Cancel = true;
       return;
     }
     sheet.SetCell(cell, col, row);
       }
       RecalculateAndShow();
       gui.SetCyclicError("Cyclic dependency");
 }
Пример #28
0
Файл: GUI.cs Проект: Dugin13/P10
 // Painting arrows to dependents and precedents of cell ca
 private void DrawDependents(Graphics g, Pen pen, int depth, CellAddr ca, HashSet<CellAddr> done)
 {
     if (depth > 0 && !done.Contains(ca)) {
     done.Add(ca);
     Cell cell = sheet[ca];
     if (cell != null) {
       cell.ForEachSupported(delegate(Sheet suppSheet, int suppCol, int suppRow) {
     CellAddr dependent = new CellAddr(suppCol, suppRow);
     if (suppSheet == sheet) {
       CellToCellArrow(g, pen, ca, dependent);
       DrawDependents(g, pen, depth - 1, dependent, done);
     }
       });
     }
       }
 }
Пример #29
0
Файл: GUI.cs Проект: Dugin13/P10
 public void SetCurrentCell(String text)
 {
     CellAddr ca = new CellAddr(dgv.CurrentCellAddress);
       SetCell(ca.col, ca.row, text);
 }
Пример #30
0
 public abstract Value View(CellAddr ulCa, CellAddr lrCa);
Пример #31
0
 public SheetTab(WorkbookForm gui, Sheet sheet)
     : base(sheet.Name)
 {
     this.gui            = gui;
     this.sheet          = sheet;
     this.Name           = sheet.Name;
     this.dgv            = new DataGridView();
     dgv.ShowEditingIcon = false;
     dgv.Dock            = DockStyle.Fill;
     Dock = DockStyle.Fill;
     // Display formula in the current cell and computed value in other cells
     dgv.CellFormatting +=
         delegate(Object sender, DataGridViewCellFormattingEventArgs e) {
         int col = e.ColumnIndex, row = e.RowIndex;
         if (col == dgv.CurrentCellAddress.X && row == dgv.CurrentCellAddress.Y)
         {
             Object obj = sheet.Show(col, row);
             if (obj != null)
             {
                 e.Value             = obj;
                 e.FormattingApplied = true;
             }
         }
         else
         {
             Object obj = sheet.ShowValue(col, row);
             if (obj != null)
             {
                 e.Value             = obj;
                 e.FormattingApplied = true;
             }
         }
     };
     // Show current cell's address, and show formula in formula box
     dgv.CellEnter +=
         delegate(Object sender, DataGridViewCellEventArgs arg) {
         int row = arg.RowIndex, col = arg.ColumnIndex;
         dgv.TopLeftHeaderCell.Value = new CellAddr(col, row).ToString();
         gui.formulaBox.Text         = (String)dgv.CurrentCell.FormattedValue;
     };
     // Check that cell's contents is well-formed after edit
     dgv.CellValidating +=
         delegate(Object sender, DataGridViewCellValidatingEventArgs arg) {
         if (dgv.IsCurrentCellInEditMode)                           // Update only if cell was edited
         {
             int    row = arg.RowIndex, col = arg.ColumnIndex;
             Object value = arg.FormattedValue;
             if (value != null)
             {
                 SetCell(col, row, value.ToString(), arg);
             }
         }
     };
     // Experiment with painting on the data grid view
     dgv.Paint += delegate(Object sender, PaintEventArgs arg) {
         base.OnPaint(arg);
         // Update column and row offset tables for drawing arrows between cells:
         int offset = dgv.RowHeadersWidth;
         for (int col = 0; col < sheet.Cols; col++)
         {
             colOffset[col] = offset;
             offset        += dgv.Columns[col].Width;
         }
         colOffset[sheet.Cols] = offset;
         offset = dgv.ColumnHeadersHeight;
         for (int row = 0; row < sheet.Rows; row++)
         {
             rowOffset[row] = offset;
             offset        += dgv.Rows[row].Height;
         }
         rowOffset[sheet.Rows] = offset;
         Pen pen = new Pen(Color.Blue, 1);
         pen.EndCap   = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
         pen.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor;
         if (dgv.SelectedCells.Count > 0)
         {
             DataGridViewCell dgvc = dgv.SelectedCells[0];
             CellAddr         ca   = new CellAddr(dgvc.ColumnIndex, dgvc.RowIndex);
             Graphics         g    = arg.Graphics;
             g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
             int x = dgv.RowHeadersWidth,
                 y = dgv.ColumnHeadersHeight,
                 w = dgv.DisplayRectangle.Width - x,
                 h = dgv.DisplayRectangle.Height - y;
             // Clip headers *before* the scroll translation/transform
             g.Clip      = new Region(new Rectangle(x, y, w, h));
             g.Transform = new System.Drawing.Drawing2D.Matrix(1,
                                                               0,
                                                               0,
                                                               1,
                                                               -dgv.HorizontalScrollingOffset,
                                                               -dgv.VerticalScrollingOffset);
             SupportArea.IdempotentForeach = false;                                              // Draw all arrows into a cell
             DrawDependents(g, pen, gui.dependentsDepth, ca, new HashSet <CellAddr>());
             DrawPrecedents(g, pen, gui.precedentsDepth, ca, new HashSet <CellAddr>());
         }
     };
     dgv.SelectionChanged += delegate(Object sender, EventArgs arg) {
         if (gui.dependentsDepth != 0 || gui.precedentsDepth != 0)
         {
             gui.dependentsDepth = gui.precedentsDepth = 0;
             Refresh();
         }
     };
     // Strange: to hold sheet, we need an extra row, but not an extra column?
     dgv.ColumnCount = sheet.Cols;
     dgv.RowCount    = sheet.Rows + 1;
     // Allocate offset tables to assist drawing arrows between cells
     colOffset = new int[sheet.Cols + 1];
     rowOffset = new int[sheet.Rows + 1];
     dgv.AllowUserToAddRows = false;
     // Put labels on columns and rows, disable (meaningless) row sorting:
     for (int col = 0; col < dgv.ColumnCount; col++)
     {
         dgv.Columns[col].Name     = CellAddr.ColumnName(col);
         dgv.Columns[col].SortMode = DataGridViewColumnSortMode.NotSortable;
     }
     for (int row = 0; row < dgv.RowCount; row++)
     {
         dgv.Rows[row].HeaderCell.Value = (row + 1).ToString();
     }
     if (sheet.IsFunctionSheet)
     {
         DataGridViewCellStyle cellStyle = new DataGridViewCellStyle();
         cellStyle.BackColor = Color.LightPink;
         dgv.ColumnHeadersDefaultCellStyle = dgv.RowHeadersDefaultCellStyle = cellStyle;
     }
     // Somewhat arbitrary extension of the width -- using
     // Graphics.MeasureString("0000", dgv.Font) would be better
     dgv.RowHeadersWidth += 20;
     Controls.Add(dgv);
 }
Пример #32
0
		public abstract Value View(CellAddr ulCa, CellAddr lrCa);
Пример #33
0
		public override Value View(CellAddr ulCa, CellAddr lrCa) { return new ArrayExplicit(ulCa.Offset(this.ulCa), lrCa.Offset(this.ulCa), values); }
Пример #34
0
Файл: GUI.cs Проект: Dugin13/P10
 // Paste from the Clipboard.  Need to distinguish:
 // 1. Paste from Corecalc formula Copy: preserve sharing
 // 2. Paste from Corecalc cell Cut: adjust referring cells and this, if formula
 // 3. Paste from text (e.g. from Excel), parse to new cell
 public void Paste()
 {
     if (Clipboard.ContainsData(ClipboardCell.COPIED_CELL)) {
     // Copy Corecalc cell
     ClipboardCell cc = (ClipboardCell)Clipboard.GetData(ClipboardCell.COPIED_CELL);
     Console.WriteLine("Pasting copied cell " + Clipboard.GetText());
     Cell cell = sheet.workbook[cc.FromSheet][cc.FromCellAddr];
     int col, row, cols, rows;
     GetSelectedColsRows(out col, out row, out cols, out rows);
     sheet.PasteCell(cell, col, row, cols, rows);
     RecalculateAndShow();
       } else if (Clipboard.ContainsData(ClipboardCell.CUT_CELL)) {
     // Move Corecalc cell
     Console.WriteLine("Pasting moved cell not implemented.");
       } else if (Clipboard.ContainsText()) {
     // Insert text (from external source)
     CellAddr ca = new CellAddr(dgv.CurrentCellAddress);
     String text = Clipboard.GetText();
     Console.WriteLine("Pasting text " + text);
     SetCell(ca.col, ca.row, text);
       }
 }
Пример #35
0
 // Get cell value from array value
 public virtual Value this[CellAddr ca] {
     get { return(this[ca.col, ca.row]); }
 }
Пример #36
0
Файл: GUI.cs Проект: Dugin13/P10
 public void SetCellErrorText(CellAddr ca, String message)
 {
     dgv[ca.col, ca.row].ErrorText = message;
 }
Пример #37
0
		public override string ToString() {
			CellAddr ulCa = new CellAddr(colInt.min, rowInt.min),
					 lrCa = new CellAddr(colInt.max, rowInt.max);
			return String.Format("{0}!{1}:{2}", sheet.Name, ulCa, lrCa);
		}
Пример #38
0
Файл: GUI.cs Проект: Dugin13/P10
 private void CellToCellArrow(Graphics g, Pen pen, CellAddr ca1, CellAddr ca2)
 {
     if (dgv[ca1.col, ca1.row].Displayed || dgv[ca2.col, ca2.row].Displayed) {
     // Sadly, dgv.GetCellDisplayRectangle returns Empty outside visible area
     int x1 = (colOffset[ca1.col] + colOffset[ca1.col + 1]) / 2,
     y1 = (rowOffset[ca1.row] + rowOffset[ca1.row + 1]) / 2,
     x2 = (colOffset[ca2.col] + colOffset[ca2.col + 1]) / 2,
     y2 = (rowOffset[ca2.row] + rowOffset[ca2.row + 1]) / 2;
     g.DrawLine(pen, x1, y1, x2, y2);
       }
 }
Пример #39
0
        public void SetCurrentCell(String text)
        {
            CellAddr ca = new CellAddr(dgv.CurrentCellAddress);

            SetCell(ca.col, ca.row, text);
        }
Пример #40
0
Файл: GUI.cs Проект: Dugin13/P10
 private void DrawPrecedents(Graphics g, Pen pen, int depth, CellAddr ca, HashSet<CellAddr> done)
 {
     if (depth > 0 && !done.Contains(ca)) {
     done.Add(ca);
     Cell cell = sheet[ca];
     if (cell != null) {
       cell.ForEachReferred(sheet, ca.col, ca.row, delegate(FullCellAddr precedent) {
     if (precedent.sheet == sheet) {
       CellToCellArrow(g, pen, precedent.ca, ca);
       DrawPrecedents(g, pen, depth-1, precedent.ca, done);
     }
       });
     }
       }
 }
Пример #41
0
 public void SetCellErrorText(CellAddr ca, String message)
 {
     dgv[ca.col, ca.row].ErrorText = message;
 }
Пример #42
0
Файл: GUI.cs Проект: Dugin13/P10
 public ClipboardCell(String fromSheet, CellAddr fromCellAddr)
 {
     this.FromSheet = fromSheet;
       this.FromCellAddr = fromCellAddr;
 }
Пример #43
0
 public override Value Slice(CellAddr ulCa, CellAddr lrCa)
 {
     return(View(ulCa, lrCa));
 }
Пример #44
0
		public abstract Value Slice(CellAddr ulCa, CellAddr lrCa);
Пример #45
0
		private readonly CellAddr ca; // Cell's location within array value

		public ArrayFormula(CachedArrayFormula caf, CellAddr ca) {
			this.caf = caf;
			this.ca = ca;
		}
Пример #46
0
 public override Value View(CellAddr ulCa, CellAddr lrCa)
 {
     return(new ArrayExplicit(ulCa.Offset(this.ulCa), lrCa.Offset(this.ulCa), values));
 }
Пример #47
0
 public abstract Value Slice(CellAddr ulCa, CellAddr lrCa);
Пример #48
0
Файл: GUI.cs Проект: Dugin13/P10
 // Copy sheet's currently active cell to Clipboard, also in text format
 public void Copy()
 {
     CellAddr ca = new CellAddr(dgv.CurrentCellAddress);
       DataObject data = new DataObject();
       data.SetData(DataFormats.Text, sheet[ca].Show(ca.col, ca.row, sheet.workbook.format));
       data.SetData(ClipboardCell.COPIED_CELL, new ClipboardCell(sheet.Name, ca));
       Clipboard.Clear();
       Clipboard.SetDataObject(data, false);
 }
Пример #49
0
        private readonly CellAddr ca;           // Cell's location within array value

        public ArrayFormula(CachedArrayFormula caf, CellAddr ca)
        {
            this.caf = caf;
            this.ca  = ca;
        }
Пример #50
0
		public override Value Slice(CellAddr ulCa, CellAddr lrCa) { return View(ulCa, lrCa); }
Пример #51
0
		// Get cell value from array value
		public virtual Value this[CellAddr ca] {
			get { return this[ca.col, ca.row]; }
		}