protected override Size MeasureOverride(Size availableSize) { _maxLevel = GetMaxLevel(Orientation); if (_maxLevel == -1) { return(availableSize); } int rowOrColStartIndex = GetRowOrColumnStartIndex(); int rowOrColCount = GetRowOrColumnCount(); // 区域无变化 if (rowOrColStartIndex == _rowOrColStartIndex && rowOrColCount == _rowOrColCount) { foreach (UIElement elem in Children) { elem.Measure(availableSize); } return(availableSize); } _rowOrColStartIndex = rowOrColStartIndex; _rowOrColCount = rowOrColCount; MeasureInitialization(); double buttonSize = CalcMinWidthOrHeight(availableSize, Orientation); while (rowOrColStartIndex < rowOrColCount) { RangeGroupInfo info = null; if (Orientation == Windows.UI.Xaml.Controls.Orientation.Horizontal) { info = _excel.ActiveSheet.RowRangeGroup.Find(rowOrColStartIndex, 0); } else if (Orientation == Windows.UI.Xaml.Controls.Orientation.Vertical) { info = _excel.ActiveSheet.ColumnRangeGroup.Find(rowOrColStartIndex, 0); } if (info != null) { rowOrColStartIndex = info.End + 1; MeasureGroups(availableSize, info, buttonSize); } rowOrColStartIndex++; } switch (Orientation) { case Windows.UI.Xaml.Controls.Orientation.Vertical: MeasureBottomBorder(availableSize); break; case Windows.UI.Xaml.Controls.Orientation.Horizontal: MeasureRightBorder(availableSize); break; } return(availableSize); }
/// <summary> /// Saves the state for undoing the action. /// </summary> public void SaveState() { Dictionary <int, bool> dictionary = null; if (((_sheet != null) && (_rowGroupHeaderExpandExtent != null)) && (_sheet.RowRangeGroup != null)) { int level = _rowGroupHeaderExpandExtent.Level; dictionary = new Dictionary <int, bool>(); for (int i = 0; i <= level; i++) { int index = 0; int rowCount = _sheet.RowCount; RangeGroupDirection direction = _sheet.RowRangeGroup.Direction; while (index < rowCount) { RangeGroupInfo info = _sheet.RowRangeGroup.Find(index, i); if (info != null) { int num5 = -1; switch (direction) { case RangeGroupDirection.Backward: num5 = info.Start - 1; break; case RangeGroupDirection.Forward: num5 = info.End + 1; break; } bool flag = info.State == GroupState.Collapsed; if (!dictionary.ContainsKey(num5)) { dictionary.Add(num5, flag); } index += (info.End - info.Start) + 1; } index++; } } } _oldStatus = dictionary; }
/// <summary> /// Saves the state for undoing the action. /// </summary> public void SaveState() { List <ColumnUngroupExtent> list = new List <ColumnUngroupExtent>(); if (((_sheet != null) && (_columnUngroupExtent != null)) && (_sheet.ColumnRangeGroup != null)) { int index = _columnUngroupExtent.Index; int count = _columnUngroupExtent.Count; for (int i = index; i < (index + count); i++) { RangeGroupInfo info = _sheet.ColumnRangeGroup.Find(i, 0); if (info != null) { list.Add(new ColumnUngroupExtent(i, Math.Min((int)(index + count), (int)(info.End + 1)) - i)); i = info.End; } } } _cachedUngroups = list; }
void ShowColumnRangeGroup(Excel excel) { int index = _columnExpandExtent.Index; if ((index >= 0) && (index < _sheet.ColumnCount)) { ViewportInfo viewportInfo = excel.GetViewportInfo(); if (excel.ActiveSheet.ColumnRangeGroup.Direction == RangeGroupDirection.Forward) { RangeGroupInfo info2 = _sheet.ColumnRangeGroup.Find(index - 1, _columnExpandExtent.Level); if (info2 != null) { int start = info2.Start; int rightColumn = index; int viewportIndex = _columnExpandExtent.ViewportIndex; if (_sheet.ColumnRangeGroup.Data.GetCollapsed(index)) { if ((viewportIndex < 0) || (viewportIndex >= viewportInfo.ColumnViewportCount)) { return; } start = index; } else { if (viewportIndex < 0) { return; } if (viewportIndex == 0) { if (start < excel.ActiveSheet.FrozenColumnCount) { start = excel.ActiveSheet.FrozenColumnCount; } } else if (viewportIndex >= viewportInfo.ColumnViewportCount) { if (start >= (excel.ActiveSheet.ColumnCount - excel.ActiveSheet.FrozenTrailingColumnCount)) { return; } start = Math.Max(start, excel.ActiveSheet.FrozenColumnCount); rightColumn = (excel.ActiveSheet.ColumnCount - excel.ActiveSheet.FrozenTrailingColumnCount) - 1; viewportIndex--; } } int viewportLeftColumn = excel.GetViewportLeftColumn(viewportIndex); if (start < viewportLeftColumn) { viewportLeftColumn = start; } double viewportWidth = excel.GetViewportWidth(viewportIndex); double num7 = NavigatorHelper.GetColumnWidth(excel.ActiveSheet, viewportLeftColumn, rightColumn); if (num7 > viewportWidth) { viewportLeftColumn = NavigatorHelper.GetNewLeftColumn(excel.ActiveSheet, viewportLeftColumn, num7 - viewportWidth); } excel.SetViewportLeftColumn(viewportIndex, viewportLeftColumn); } } else if (_sheet.ColumnRangeGroup.Direction == RangeGroupDirection.Backward) { RangeGroupInfo info3 = _sheet.ColumnRangeGroup.Find(index + 1, _columnExpandExtent.Level); if (info3 != null) { int frozenColumnCount = index; int end = info3.End; int columnViewportIndex = _columnExpandExtent.ViewportIndex; if (_sheet.ColumnRangeGroup.Data.GetCollapsed(index)) { if ((columnViewportIndex < 0) || (columnViewportIndex >= viewportInfo.ColumnViewportCount)) { return; } end = index; } else { if (columnViewportIndex >= viewportInfo.ColumnViewportCount) { return; } if (columnViewportIndex == (viewportInfo.ColumnViewportCount - 1)) { if (end >= (excel.ActiveSheet.ColumnCount - excel.ActiveSheet.FrozenTrailingColumnCount)) { end = (excel.ActiveSheet.ColumnCount - excel.ActiveSheet.FrozenTrailingColumnCount) - 1; } } else if (columnViewportIndex < 0) { if (end < excel.ActiveSheet.FrozenColumnCount) { return; } frozenColumnCount = excel.ActiveSheet.FrozenColumnCount; end = Math.Min(end, (excel.ActiveSheet.ColumnCount - excel.ActiveSheet.FrozenTrailingColumnCount) - 1); columnViewportIndex++; } } int leftColumn = excel.GetViewportLeftColumn(columnViewportIndex); if (frozenColumnCount < leftColumn) { excel.SetViewportLeftColumn(columnViewportIndex, frozenColumnCount); } else { double num12 = excel.GetViewportWidth(columnViewportIndex); double num13 = NavigatorHelper.GetColumnWidth(excel.ActiveSheet, leftColumn, end); if (num13 > num12) { leftColumn = NavigatorHelper.GetNewLeftColumn(excel.ActiveSheet, leftColumn, num13 - num12); excel.SetViewportLeftColumn(columnViewportIndex, Math.Min(frozenColumnCount, leftColumn)); } } } } } }
void ShowRowRangeGroup(Excel excel) { int index = _rowExpandExtent.Index; if ((index >= 0) && (index < _sheet.RowCount)) { ViewportInfo viewportInfo = excel.GetViewportInfo(); if (excel.ActiveSheet.RowRangeGroup.Direction == RangeGroupDirection.Forward) { RangeGroupInfo info2 = _sheet.RowRangeGroup.Find(index - 1, _rowExpandExtent.Level); if (info2 != null) { int start = info2.Start; int bottonRow = index; int viewportIndex = _rowExpandExtent.ViewportIndex; if (_sheet.RowRangeGroup.Data.GetCollapsed(index)) { if ((viewportIndex < 0) || (viewportIndex >= viewportInfo.RowViewportCount)) { return; } start = index; } else { if (viewportIndex < 0) { return; } if (viewportIndex == 0) { if (start < excel.ActiveSheet.FrozenRowCount) { start = excel.ActiveSheet.FrozenRowCount; } } else if (viewportIndex >= viewportInfo.RowViewportCount) { if (start >= (excel.ActiveSheet.RowCount - excel.ActiveSheet.FrozenTrailingRowCount)) { return; } start = Math.Max(start, excel.ActiveSheet.FrozenRowCount); bottonRow = (excel.ActiveSheet.RowCount - excel.ActiveSheet.FrozenTrailingRowCount) - 1; viewportIndex--; } } int viewportTopRow = excel.GetViewportTopRow(viewportIndex); if (start < viewportTopRow) { viewportTopRow = start; } double viewportHeight = excel.GetViewportHeight(viewportIndex); double num7 = NavigatorHelper.GetRowHeight(excel.ActiveSheet, viewportTopRow, bottonRow); if (num7 > viewportHeight) { viewportTopRow = NavigatorHelper.GetNewTopRow(excel.ActiveSheet, viewportTopRow, num7 - viewportHeight); } excel.SetViewportTopRow(viewportIndex, viewportTopRow); } } else if (_sheet.RowRangeGroup.Direction == RangeGroupDirection.Backward) { RangeGroupInfo info3 = _sheet.RowRangeGroup.Find(index + 1, _rowExpandExtent.Level); if (info3 != null) { int frozenRowCount = index; int end = info3.End; int rowViewportIndex = _rowExpandExtent.ViewportIndex; if (_sheet.RowRangeGroup.Data.GetCollapsed(index)) { if ((rowViewportIndex < 0) || (rowViewportIndex >= viewportInfo.RowViewportCount)) { return; } end = index; } else { if (rowViewportIndex >= viewportInfo.RowViewportCount) { return; } if (rowViewportIndex == (viewportInfo.RowViewportCount - 1)) { if (end >= (excel.ActiveSheet.RowCount - excel.ActiveSheet.FrozenTrailingRowCount)) { end = (excel.ActiveSheet.RowCount - excel.ActiveSheet.FrozenTrailingRowCount) - 1; } } else if (rowViewportIndex < 0) { if (end < excel.ActiveSheet.FrozenRowCount) { return; } frozenRowCount = excel.ActiveSheet.FrozenRowCount; end = Math.Min(end, (excel.ActiveSheet.RowCount - excel.ActiveSheet.FrozenTrailingRowCount) - 1); rowViewportIndex++; } } int topRow = excel.GetViewportTopRow(rowViewportIndex); if (frozenRowCount < topRow) { excel.SetViewportTopRow(rowViewportIndex, frozenRowCount); } else { double num12 = excel.GetViewportHeight(rowViewportIndex); double num13 = NavigatorHelper.GetRowHeight(excel.ActiveSheet, topRow, end); if (num13 > num12) { topRow = NavigatorHelper.GetNewTopRow(excel.ActiveSheet, topRow, num13 - num12); excel.SetViewportTopRow(rowViewportIndex, Math.Min(frozenRowCount, topRow)); } } } } } }
void MeasureGroups(Size availableSize, RangeGroupInfo group, double buttonSize) { RangeGroupDirection groupDirection = GetGroupDirection(); int viewportStartIndex = GetViewportStartIndex(); int viewportEndIndex = GetViewportEndIndex(); int start = group.Start; int end = group.End; if (group.State == GroupState.Collapsed) { // 折叠状态 GroupButton button = new GroupButton(); button.Click += GroupButton_Click; button.IsExpanded = false; button.Level = group.Level; GroupButtonInfo info6 = new GroupButtonInfo(button); switch (groupDirection) { case RangeGroupDirection.Forward: { int num13 = end + 1; if ((num13 >= viewportStartIndex) && (num13 <= viewportEndIndex)) { Children.Add(button); button.Measure(new Size(buttonSize, buttonSize)); button.Index = num13; info6.LineDirection = RangeGroupDirection.Forward; _groupButtonInfos.Add(info6); return; } break; } case RangeGroupDirection.Backward: { int num14 = start - 1; if ((num14 >= viewportStartIndex) && (num14 <= viewportEndIndex)) { Children.Add(button); button.Measure(new Size(buttonSize, buttonSize)); button.Index = num14; info6.LineDirection = RangeGroupDirection.Backward; _groupButtonInfos.Add(info6); } break; } } } else { // 展开状态 bool flag = true; RangeGroupInfo parent = group.Parent; if ((parent != null) && (((groupDirection == RangeGroupDirection.Backward) && (group.Start == parent.Start)) || ((groupDirection == RangeGroupDirection.Forward) && (group.End == parent.End)))) { flag = false; } if (flag) { GroupButton presenter = new GroupButton(); presenter.Click += GroupButton_Click; presenter.IsExpanded = true; presenter.Level = group.Level; GroupButtonInfo info2 = new GroupButtonInfo(presenter); Rectangle rectangle = new Rectangle(); rectangle.Fill = PaintedBrush; info2.Line = rectangle; switch (groupDirection) { case RangeGroupDirection.Forward: { int num5 = end + 1; if ((num5 >= viewportStartIndex) && (num5 <= viewportEndIndex)) { presenter.Index = num5; info2.LineDirection = RangeGroupDirection.Forward; Children.Add(presenter); presenter.Measure(new Size(buttonSize, buttonSize)); Children.Add(rectangle); rectangle.Measure(new Size(availableSize.Width, availableSize.Height)); _groupButtonInfos.Add(info2); } break; } case RangeGroupDirection.Backward: { int num6 = start - 1; if ((num6 >= viewportStartIndex) && (num6 <= viewportEndIndex)) { presenter.Index = num6; info2.LineDirection = RangeGroupDirection.Backward; Children.Add(presenter); presenter.Measure(new Size(buttonSize, buttonSize)); Children.Add(rectangle); rectangle.Measure(new Size(availableSize.Width, availableSize.Height)); _groupButtonInfos.Add(info2); } break; } } } if ((start <= viewportEndIndex) && (end >= viewportStartIndex)) { int num7 = Math.Max(viewportStartIndex, start); int num8 = Math.Min(viewportEndIndex, end); if (flag) { Rectangle line = new Rectangle(); line.Fill = PaintedBrush; GroupLineInfo info3 = new GroupLineInfo(line) { Start = num7, End = num8, Level = group.Level }; Children.Add(line); line.Measure(new Size(2.0, availableSize.Height)); if (((groupDirection == RangeGroupDirection.Forward) && (num7 == start)) || ((groupDirection == RangeGroupDirection.Backward) && (num8 == end))) { Rectangle rectangle3 = new Rectangle(); rectangle3.Fill = PaintedBrush; info3.StartLine = rectangle3; Children.Add(rectangle3); rectangle3.Measure(new Size(availableSize.Width, availableSize.Height)); } _groupLineInfos.Add(info3); } List <int> list = new List <int>(); for (int i = num7; i <= num8; i++) { list.Add(i); } foreach (RangeGroupInfo info4 in group.Children) { if (info4.State == GroupState.Collapsed) { for (int j = info4.Start; j <= info4.End; j++) { list.Remove(j); } } switch (groupDirection) { case RangeGroupDirection.Forward: list.Remove(info4.End + 1); break; case RangeGroupDirection.Backward: list.Remove(info4.Start - 1); break; } MeasureGroups(availableSize, info4, buttonSize); if (((groupDirection == RangeGroupDirection.Backward) && (group.Start == info4.Start)) || ((groupDirection == RangeGroupDirection.Forward) && (group.End == info4.End))) { for (int k = info4.Start; k <= info4.End; k++) { list.Remove(k); } } } if (list.Count > 0) { foreach (int num12 in list) { Ellipse ellipse = new Ellipse(); ellipse.Fill = PaintedBrush; GroupDotInfo info5 = new GroupDotInfo(ellipse) { Index = num12, Level = group.Level + 1 }; Children.Add(ellipse); ellipse.Measure(_dotSize); _groupDotInfos.Add(info5); } } } } }