Beispiel #1
0
        protected static int MoveRef(TBaseRefToken reft, ref int RowCol, int AbsRowCol, int InsPos, int Offs, int FmlaRowCol, bool RowRel, bool RefInside, bool FmlaInside, int MaxRowCol, bool CheckInside)
        {
            if (RowRel)
            {
                if (FmlaRowCol < 0)
                {
                    return(AbsRowCol);                //this is a name or similar, in this case we don't update refs.
                }
                if (RefInside ^ FmlaInside)
                {
                    if (CheckInside) //Here only matters if RefInside is true. If FmlaInside is true, the ref will be destroyed anyway.
                    {
                        if (InsPos >= 0 && RowCol >= InsPos && RowCol < InsPos - Offs)
                        {
                            reft.CreateInvalidRef();                                                            //deleted relative ref
                        }
                    }

                    int rofs = FmlaInside ? -Offs : Offs;
                    int a    = TBaseRefToken.WrapSigned(RowCol + rofs, MaxRowCol);
                    RowCol    = a;
                    AbsRowCol = TBaseRefToken.WrapSigned(FmlaRowCol + a, MaxRowCol);
                }
            }
            else
            {
                if (RefInside)
                {
                    reft.IncRowCol(ref RowCol, InsPos, Offs, MaxRowCol, CheckInside);
                    AbsRowCol = RowCol;
                }
            }
            return(AbsRowCol);
        }
Beispiel #2
0
        protected override void DoArea(TAreaToken areat, bool RefIsInInsertingSheet)
        {
            int r1 = areat.Row1;
            int r2 = areat.Row2;
            int c1 = areat.Col1;
            int c2 = areat.Col2;

            if (RefIsInInsertingSheet)
            {
                TXlsCellRange NewRange = CellRange.Offset(NewRow, NewCol);

                bool RowRel1 = areat.CanHaveRelativeOffsets && !areat.RowAbs1;  //CanHaveRelativeOffsets is true for RefN tokens.
                bool ColRel1 = areat.CanHaveRelativeOffsets && !areat.ColAbs1;
                bool RowRel2 = areat.CanHaveRelativeOffsets && !areat.RowAbs2;
                bool ColRel2 = areat.CanHaveRelativeOffsets && !areat.ColAbs2;

                if (RowRel1)
                {
                    r1 = TBaseRefToken.WrapRow(FmlaRow + r1, false);
                }
                if (ColRel1)
                {
                    c1 = TBaseRefToken.WrapColumn(FmlaCol + c1, false);
                }
                if (RowRel2)
                {
                    r2 = TBaseRefToken.WrapRow(FmlaRow + r2, false);
                }
                if (ColRel2)
                {
                    c2 = TBaseRefToken.WrapColumn(FmlaCol + c2, false);
                }

                bool RefInside  = CellRange.HasRow(r1) && CellRange.HasCol(c1) && CellRange.HasRow(r2) && CellRange.HasCol(c2);
                bool FmlaInside = CellRange.HasRow(FmlaRow) && CellRange.HasCol(FmlaCol);

                //only if the ref was *not* on the original range.
                if (!RefInside && NewRange.HasRow(r1) && NewRange.HasCol(c1) && NewRange.HasRow(r2) && NewRange.HasCol(c2))
                {
                    areat.CreateInvalidRef();
                }
                else
                {
                    r1 = MoveRef(areat, ref areat.Row1, r1, 0, NewRow - CellRange.Top, FmlaRow, RowRel1, RefInside, FmlaInside, FlxConsts.Max_Rows, false);
                    c1 = MoveRef(areat, ref areat.Col1, c1, 0, NewCol - CellRange.Left, FmlaCol, ColRel1, RefInside, FmlaInside, FlxConsts.Max_Columns, false);
                    r2 = MoveRef(areat, ref areat.Row2, r2, 0, NewRow - CellRange.Top, FmlaRow, RowRel2, RefInside, FmlaInside, FlxConsts.Max_Rows, false);
                    c2 = MoveRef(areat, ref areat.Col2, c2, 0, NewCol - CellRange.Left, FmlaCol, ColRel2, RefInside, FmlaInside, FlxConsts.Max_Columns, false);
                }
            }
            if (Bounds != null)
            {
                Bounds.AddRow(r1);
                Bounds.AddRow(r2);
                Bounds.AddCol(c1);
                Bounds.AddCol(c2);
            }
        }
Beispiel #3
0
        private void OffsetCopy(TBaseRefToken reft, ref int RowCol, int CopyOffset, int MaxRowCol, bool RowColAbs, bool ForgetAbsolute)
        {
            if (reft.CanHaveRelativeOffsets && !RowColAbs)
            {
                return;                                             //Offsets never have to be adapted when copying
            }
            bool AbsoluteRef = AllowedAbsolute && RowColAbs;

            if (!AbsoluteRef || ForgetAbsolute)
            {
                reft.IncRowCol(ref RowCol, -1, CopyOffset, MaxRowCol, true);                                  //Fix the copy.
            }
        }
Beispiel #4
0
        protected override void DoRef(TRefToken reft, bool RefIsInInsertingSheet)
        {
            int r = reft.Row; int c = reft.Col;

            if (RefIsInInsertingSheet)
            {
                TXlsCellRange NewRange = CellRange.Offset(NewRow, NewCol);

                bool RowIsOffset = reft.CanHaveRelativeOffsets && !reft.RowAbs;  //CanHaveRelativeOffsets is true for RefN tokens.
                bool ColIsOffset = reft.CanHaveRelativeOffsets && !reft.ColAbs;

                if (RowIsOffset)
                {
                    r = TBaseRefToken.WrapRow(FmlaRow + r, false);
                }
                if (ColIsOffset)
                {
                    c = TBaseRefToken.WrapColumn(FmlaCol + c, false);
                }

                bool RefInside  = CellRange.HasRow(r) && CellRange.HasCol(c);
                bool FmlaInside = CellRange.HasRow(FmlaRow) && CellRange.HasCol(FmlaCol);

                //only if the ref was *not* on the original range.
                if (!RefInside && NewRange.HasRow(r) && NewRange.HasCol(c))
                {
                    reft.CreateInvalidRef();
                }
                else
                {
                    r = MoveRef(reft, ref reft.Row, r, 0, NewRow - CellRange.Top, FmlaRow, RowIsOffset, RefInside, FmlaInside, FlxConsts.Max_Rows, false);
                    c = MoveRef(reft, ref reft.Col, c, 0, NewCol - CellRange.Left, FmlaCol, ColIsOffset, RefInside, FmlaInside, FlxConsts.Max_Columns, false);
                }
            }

            if (Bounds != null)
            {
                Bounds.AddRow(r);
                Bounds.AddCol(c);
            }
        }
Beispiel #5
0
        protected override void DoRef(TRefToken reft, bool RefIsInInsertingSheet)
        {
            int r = reft.Row;
            int c = reft.Col;

            if (RefIsInInsertingSheet)
            {
                bool RowIsOffset = reft.CanHaveRelativeOffsets && !reft.RowAbs;  //CanHaveRelativeOffsets is true for RefN tokens.
                bool ColIsOffset = reft.CanHaveRelativeOffsets && !reft.ColAbs;

                if (RowIsOffset)
                {
                    r = TBaseRefToken.WrapRow(FmlaRow + r, false);
                }
                if (ColIsOffset)
                {
                    c = TBaseRefToken.WrapColumn(FmlaCol + c, false);
                }

                bool FmlaInsideDown  = (FmlaRow >= CellRange.Top) && CellRange.HasCol(FmlaCol);
                bool FmlaInsideRight = (FmlaCol >= CellRange.Left) && CellRange.HasRow(FmlaRow);
                bool RefInsideDown   = (r >= CellRange.Top) && (CellRange.HasCol(c));
                bool RefInsideRight  = (c >= CellRange.Left) && (CellRange.HasRow(r));

                r = MoveRef(reft, ref reft.Row, r, CellRange.Top, RowCount * CellRange.RowCount, FmlaRow, RowIsOffset, RefInsideDown, FmlaInsideDown, FlxConsts.Max_Rows, true);
                c = MoveRef(reft, ref reft.Col, c, CellRange.Left, ColCount * CellRange.ColCount, FmlaCol, ColIsOffset, RefInsideRight, FmlaInsideRight, FlxConsts.Max_Columns, true);
            }

            bool ForgetAbsolute = SemiAbsoluteMode && CellRange.HasRow(r) && CellRange.HasCol(c);

            OffsetCopy(reft, ref reft.Row, CopyRowOffset, FlxConsts.Max_Rows, reft.RowAbs, ForgetAbsolute);
            OffsetCopy(reft, ref reft.Col, CopyColOffset, FlxConsts.Max_Columns, reft.ColAbs, ForgetAbsolute);

            if (Bounds != null)
            {
                Bounds.AddRow(reft.Row);
                Bounds.AddCol(reft.Col);
            }
        }
Beispiel #6
0
        protected override void DoArea(TAreaToken areat, bool RefIsInInsertingSheet)
        {
            int r1 = areat.Row1;
            int r2 = areat.Row2;
            int c1 = areat.Col1;
            int c2 = areat.Col2;

            if (RefIsInInsertingSheet)
            {
                bool RowRel1 = areat.CanHaveRelativeOffsets && !areat.RowAbs1;  //CanHaveRelativeOffsets is true for RefN tokens.
                bool ColRel1 = areat.CanHaveRelativeOffsets && !areat.ColAbs1;
                bool RowRel2 = areat.CanHaveRelativeOffsets && !areat.RowAbs2;
                bool ColRel2 = areat.CanHaveRelativeOffsets && !areat.ColAbs2;

                if (RowRel1)
                {
                    r1 = TBaseRefToken.WrapRow(FmlaRow + r1, false);
                }
                if (ColRel1)
                {
                    c1 = TBaseRefToken.WrapColumn(FmlaCol + c1, false);
                }
                if (RowRel2)
                {
                    r2 = TBaseRefToken.WrapRow(FmlaRow + r2, false);
                }
                if (ColRel2)
                {
                    c2 = TBaseRefToken.WrapColumn(FmlaCol + c2, false);
                }

                bool InColRange = CellRange.HasCol(c1) && CellRange.HasCol(c2);
                if (InColRange)
                {
                    if (RowCount < 0)
                    {
                        areat.DeleteRowsArea(FmlaRow, RowCount, CellRange);  //Handles the complexities of deleting ranges.
                    }
                }

                if (RowCount > 0)
                {
                    bool FmlaInsideDown = (FmlaRow >= CellRange.Top) && CellRange.HasCol(FmlaCol);
                    bool RefInsideDown1 = r1 >= CellRange.Top && InColRange;
                    bool RefInsideDown2 = r2 >= CellRange.Top && r2 != FlxConsts.Max_Rows && InColRange;
                    r1 = MoveRef(areat, ref areat.Row1, r1, CellRange.Top, RowCount * CellRange.RowCount, FmlaRow, RowRel1, RefInsideDown1, FmlaInsideDown, FlxConsts.Max_Rows, true);
                    r2 = MoveRef(areat, ref areat.Row2, r2, CellRange.Top, RowCount * CellRange.RowCount, FmlaRow, RowRel2, RefInsideDown2, FmlaInsideDown, FlxConsts.Max_Rows, true);
                }

                bool InRowRange = CellRange.HasRow(r1) && CellRange.HasRow(r2);
                if (InRowRange)
                {
                    if (ColCount < 0)
                    {
                        areat.DeleteColsArea(FmlaCol, ColCount, CellRange);  //Handles the complexities of deleting ranges.
                    }
                }

                if (ColCount > 0)
                {
                    bool FmlaInsideRight = (FmlaCol >= CellRange.Left) && CellRange.HasRow(FmlaRow);
                    bool RefInsideRight1 = c1 >= CellRange.Left && InRowRange;
                    bool RefInsideRight2 = c2 >= CellRange.Left && c2 != FlxConsts.Max_Columns && InRowRange;
                    c1 = MoveRef(areat, ref areat.Col1, c1, CellRange.Top, ColCount * CellRange.ColCount, FmlaCol, ColRel1, RefInsideRight1, FmlaInsideRight, FlxConsts.Max_Columns, true);
                    c2 = MoveRef(areat, ref areat.Col2, c2, CellRange.Top, ColCount * CellRange.ColCount, FmlaCol, ColRel2, RefInsideRight2, FmlaInsideRight, FlxConsts.Max_Columns, true);
                }
            }


            bool ForgetAbsolute1 = SemiAbsoluteMode && CellRange.HasRow(r1) && CellRange.HasCol(c1);
            bool ForgetAbsolute2 = SemiAbsoluteMode && CellRange.HasRow(r2) && CellRange.HasCol(c2);

            OffsetCopy(areat, ref areat.Row1, CopyRowOffset, FlxConsts.Max_Rows, areat.RowAbs1, ForgetAbsolute1);
            OffsetCopy(areat, ref areat.Col1, CopyColOffset, FlxConsts.Max_Columns, areat.ColAbs1, ForgetAbsolute1);
            OffsetCopy(areat, ref areat.Row2, CopyRowOffset, FlxConsts.Max_Rows, areat.RowAbs2, ForgetAbsolute2);
            OffsetCopy(areat, ref areat.Col2, CopyColOffset, FlxConsts.Max_Columns, areat.ColAbs2, ForgetAbsolute2);

            if (Bounds != null)
            {
                Bounds.AddRow(areat.Row1);
                Bounds.AddRow(areat.Row2);
                Bounds.AddCol(areat.Col1);
                Bounds.AddCol(areat.Col2);
            }
        }