Beispiel #1
0
 /// <summary>
 /// Saves the undo information.
 /// </summary>
 public void SaveState()
 {
     double[] numArray  = null;
     bool[]   flagArray = null;
     if (((_sheet != null) && (_rows != null)) && (_rows.Length > 0))
     {
         numArray  = new double[_rows.Length];
         flagArray = new bool[_rows.Length];
         int num = _columnHeader ? _sheet.ColumnHeader.RowCount : _sheet.RowCount;
         for (int i = 0; i < _rows.Length; i++)
         {
             RowAutoFitExtent extent = _rows[i];
             if ((0 <= extent.Row) && (extent.Row < num))
             {
                 if (_columnHeader)
                 {
                     numArray[i]  = _sheet.GetRowHeight(extent.Row, SheetArea.ColumnHeader);
                     flagArray[i] = _sheet.GetRowVisible(extent.Row, SheetArea.ColumnHeader);
                 }
                 else
                 {
                     numArray[i]  = _sheet.GetRowHeight(extent.Row, SheetArea.Cells);
                     flagArray[i] = _sheet.GetRowVisible(extent.Row, SheetArea.Cells);
                 }
             }
             else
             {
                 numArray[i]  = -1.0;
                 flagArray[i] = false;
             }
         }
     }
     _oldSizes    = numArray;
     _oldVisibles = flagArray;
 }
Beispiel #2
0
        /// <summary>
        /// Undoes the row automatic fit action.
        /// </summary>
        /// <param name="sender">Object on which the action occurs.</param>
        /// <returns><c>true</c> if the undo is a success; otherwise, <c>false</c>.</returns>
        public bool Undo(object sender)
        {
            bool flag = false;

            if (((_sheet != null) && (_rows != null)) && (_rows.Length > 0))
            {
                Excel view        = sender as Excel;
                int[] rowsResized = GetRowsResized(_rows);
                base.SuspendInvalidate(sender);
                try
                {
                    if ((view != null) && view.RaiseRowHeightChanging(rowsResized, _columnHeader))
                    {
                        return(true);
                    }
                    int num2 = _columnHeader ? _sheet.ColumnHeader.RowCount : _sheet.RowCount;
                    for (int i = 0; i < _rows.Length; i++)
                    {
                        RowAutoFitExtent extent = _rows[i];
                        double           height = _oldSizes[i];
                        bool             flag3  = _oldVisibles[i];
                        if (((0 <= i) && (i < num2)) && (height != -1.0))
                        {
                            if (_columnHeader && _sheet.GetRowResizable(extent.Row, SheetArea.ColumnHeader))
                            {
                                _sheet.SetRowHeight(extent.Row, SheetArea.ColumnHeader, height);
                                _sheet.SetRowVisible(extent.Row, SheetArea.ColumnHeader, flag3);
                                flag = true;
                            }
                            else if (_sheet.GetRowResizable(extent.Row, SheetArea.Cells))
                            {
                                _sheet.SetRowHeight(extent.Row, SheetArea.Cells, height);
                                _sheet.SetRowVisible(extent.Row, SheetArea.Cells, flag3);
                                flag = true;
                            }
                        }
                    }
                }
                finally
                {
                    base.ResumeInvalidate(sender);
                }
                if (view != null)
                {
                    view.InvalidateLayout();
                    view.InvalidateViewportHorizontalArrangement(-2);
                    view.InvalidateHeaderHorizontalArrangement();
                    view.InvalidateMeasure();
                    view.RefreshRange(-1, -1, -1, -1, SheetArea.Cells | SheetArea.RowHeader);
                    view.RaiseRowHeightChanged(rowsResized, _columnHeader);
                }
            }
            return(flag);
        }
Beispiel #3
0
 /// <summary>
 /// Executes the action on the specified sender.
 /// </summary>
 /// <param name="sender">Object on which the action occurred.</param>
 public override void Execute(object sender)
 {
     if (CanExecute(sender))
     {
         Excel view        = sender as Excel;
         int[] rowsResized = GetRowsResized(_rows);
         base.SuspendInvalidate(sender);
         try
         {
             if ((view != null) && view.RaiseRowHeightChanging(rowsResized, _columnHeader))
             {
                 return;
             }
             SaveState();
             int num = _columnHeader ? _sheet.ColumnHeader.RowCount : _sheet.RowCount;
             for (int i = 0; i < _rows.Length; i++)
             {
                 RowAutoFitExtent extent = _rows[i];
                 if ((0 <= extent.Row) && (extent.Row < num))
                 {
                     if (_columnHeader && _sheet.GetRowResizable(extent.Row, SheetArea.ColumnHeader))
                     {
                         double height = Math.Ceiling(view.GetRowAutoFitValue(extent.Row, true));
                         if (height >= 0.0)
                         {
                             height = (height + 1.0) + 2.0;
                             if (height < _sheet.ColumnHeader.DefaultRowHeight)
                             {
                                 height = _sheet.ColumnHeader.DefaultRowHeight;
                             }
                         }
                         if (height != _sheet.GetRowHeight(extent.Row, SheetArea.ColumnHeader))
                         {
                             _sheet.SetRowHeight(extent.Row, SheetArea.ColumnHeader, height);
                         }
                         _sheet.SetRowVisible(extent.Row, SheetArea.ColumnHeader, true);
                     }
                     else if (_sheet.GetRowResizable(extent.Row, SheetArea.Cells))
                     {
                         double defaultRowHeight = Math.Ceiling(view.GetRowAutoFitValue(extent.Row, false));
                         if (defaultRowHeight >= 0.0)
                         {
                             defaultRowHeight = (defaultRowHeight + 1.0) + 2.0;
                             if (defaultRowHeight < _sheet.DefaultRowHeight)
                             {
                                 defaultRowHeight = _sheet.DefaultRowHeight;
                             }
                         }
                         if (defaultRowHeight != _sheet.GetRowHeight(extent.Row, SheetArea.Cells))
                         {
                             _sheet.SetRowHeight(extent.Row, SheetArea.Cells, defaultRowHeight);
                         }
                         _sheet.SetRowVisible(extent.Row, SheetArea.Cells, true);
                     }
                 }
             }
         }
         finally
         {
             base.ResumeInvalidate(sender);
         }
         if (view != null)
         {
             view.InvalidateLayout();
             view.InvalidateViewportHorizontalArrangement(-2);
             view.InvalidateHeaderHorizontalArrangement();
             view.InvalidateMeasure();
             view.RefreshRange(-1, -1, -1, -1, SheetArea.Cells | SheetArea.RowHeader);
             view.RefreshFloatingObjects();
             view.RaiseRowHeightChanged(rowsResized, _columnHeader);
         }
     }
 }