using System; using System.Diagnostics; using System.Linq; using CPF.Drawing; using CPF.ReoGrid.Core; using CPF.ReoGrid.Data; using CPF.ReoGrid.Graphics; using CPF.ReoGrid.Main; using CPF.ReoGrid.Outline; using CPF.ReoGrid.Rendering; namespace CPF.ReoGrid.Views { internal class NormalViewportController : ViewportController, IFreezableViewportController, IScrollableViewportController, IScalableViewportController { public NormalViewportController(Worksheet sheet) : base(sheet) { sheet.ViewportController = this; this.AddView(this.rightBottomSpace = new SpaceView()); this.AddView(this.leadHeadPart = new LeadHeaderView(this)); this.AddView(this.colHeaderPart2 = new ColumnHeaderView(this)); this.AddView(this.rowHeaderPart2 = new RowHeaderView(this)); this.AddView(this.rightBottomViewport = new SheetViewport(this)); this.rightBottomViewport.ScrollableDirections = ScrollDirection.Both; this.FocusView = this.rightBottomViewport; this.mainViewport = this.rightBottomViewport; } public override void SetViewVisible(ViewTypes viewFlag, bool visible) { base.SetViewVisible(viewFlag, visible); bool flag = base.IsViewVisible(ViewTypes.RowHeader); bool flag2 = base.IsViewVisible(ViewTypes.ColumnHeader); bool flag3 = base.IsViewVisible((ViewTypes)34); bool flag4 = base.IsViewVisible((ViewTypes)20); bool flag5 = (viewFlag & ViewTypes.ColumnHeader) == ViewTypes.ColumnHeader; if (flag5) { if (visible) { this.colHeaderPart2.Visible = true; this.colHeaderPart2.VisibleRegion = this.rightBottomViewport.VisibleRegion; bool flag6 = this.currentFreezePos.Col > 0; if (flag6) { this.colHeaderPart1.Visible = true; this.colHeaderPart1.VisibleRegion = this.frozenVisibleRegion; } } else { this.colHeaderPart2.Visible = false; bool flag7 = this.colHeaderPart1 != null; if (flag7) { this.colHeaderPart1.Visible = false; } } } bool flag8 = (viewFlag & ViewTypes.RowHeader) == ViewTypes.RowHeader; if (flag8) { if (visible) { this.rowHeaderPart2.Visible = true; this.rowHeaderPart2.VisibleRegion = this.rightBottomViewport.VisibleRegion; bool flag9 = this.currentFreezePos.Row > 0; if (flag9) { this.rowHeaderPart1.Visible = true; this.rowHeaderPart1.VisibleRegion = this.frozenVisibleRegion; } } else { this.rowHeaderPart2.Visible = false; bool flag10 = this.rowHeaderPart1 != null; if (flag10) { this.rowHeaderPart1.Visible = false; } } } this.leadHeadPart.Visible = base.IsViewVisible(ViewTypes.LeadHeader); bool flag11 = base.IsViewVisible(ViewTypes.RowOutline); bool flag12 = base.IsViewVisible(ViewTypes.ColOutline); bool flag13 = flag11; if (flag13) { bool flag14 = visible && this.rowOutlinePart2 == null; if (flag14) { this.rowOutlinePart2 = new RowOutlineView(this); this.rowOutlinePart2.ScrollY = this.rowHeaderPart2.ScrollY; this.AddView(this.rowOutlinePart2); } bool flag15 = this.rowOutlinePart2 != null; if (flag15) { this.rowOutlinePart2.Visible = flag11; } bool flag16 = this.rowOutlinePart1 != null; if (flag16) { this.rowOutlinePart1.Visible = flag11; } } else { bool flag17 = this.rowOutlinePart2 != null; if (flag17) { this.rowOutlinePart2.Visible = false; } bool flag18 = this.rowOutlinePart1 != null; if (flag18) { this.rowOutlinePart1.Visible = false; } } bool flag19 = flag3; if (flag19) { bool flag20 = this.rowOutlineHeadPart == null; if (flag20) { this.rowOutlineHeadPart = new RowOutlineHeaderView(this); this.AddView(this.rowOutlineHeadPart); } this.rowOutlineHeadPart.Visible = true; } else { bool flag21 = this.rowOutlineHeadPart != null; if (flag21) { this.rowOutlineHeadPart.Visible = false; } } bool flag22 = flag12; if (flag22) { bool flag23 = visible && this.colOutlinePart2 == null; if (flag23) { this.colOutlinePart2 = new ColumnOutlinePart(this); this.colOutlinePart2.ScrollX = this.colHeaderPart2.ScrollX; this.AddView(this.colOutlinePart2); } bool flag24 = this.colOutlinePart2 != null; if (flag24) { this.colOutlinePart2.Visible = flag12; } bool flag25 = this.colOutlinePart1 != null; if (flag25) { this.colOutlinePart1.Visible = flag12; } } else { bool flag26 = this.colOutlinePart2 != null; if (flag26) { this.colOutlinePart2.Visible = false; } bool flag27 = this.colOutlinePart1 != null; if (flag27) { this.colOutlinePart1.Visible = false; } } bool flag28 = flag4; if (flag28) { bool flag29 = this.colOutlineHeadPart == null; if (flag29) { this.colOutlineHeadPart = new ColumnOutlineHeadPart(this); this.AddView(this.colOutlineHeadPart); } this.colOutlineHeadPart.Visible = true; } else { bool flag30 = this.colOutlineHeadPart != null; if (flag30) { this.colOutlineHeadPart.Visible = false; } } bool flag31 = flag11 && flag12; if (flag31) { bool flag32 = this.outlineLeftTopSpace == null; if (flag32) { this.outlineLeftTopSpace = new OutlineLeftTopSpace(this); this.AddView(this.outlineLeftTopSpace); } this.outlineLeftTopSpace.Visible = visible; } else { bool flag33 = this.outlineLeftTopSpace != null; if (flag33) { this.outlineLeftTopSpace.Visible = false; } } } private Rect GetGridScaleBounds(CellPosition pos) { return this.GetGridScaleBounds(pos.Row, pos.Col); } private Rect GetGridScaleBounds(int row, int col) { CellPosition freezePos = this.worksheet.FreezePos; RowHeader rowHeader = this.worksheet.rows[freezePos.Row]; ColumnHeader columnHeader = this.worksheet.cols[freezePos.Col]; float num = (float)columnHeader.Left * this.ScaleFactor; float num2 = (float)rowHeader.Top * this.ScaleFactor; float num3 = (float)columnHeader.InnerWidth * this.ScaleFactor + 1f; float num4 = (float)rowHeader.InnerHeight * this.ScaleFactor + 1f; return new Rect(ref num, ref num2, ref num3, ref num4); } private Rect GetRangeScaledBounds(GridRegion region) { RowHeader rowHeader = this.worksheet.rows[region.startRow]; ColumnHeader columnHeader = this.worksheet.cols[region.startCol]; RowHeader rowHeader2 = this.worksheet.rows[region.endRow]; ColumnHeader columnHeader2 = this.worksheet.cols[region.endCol]; float num = (float)columnHeader.Left * this.ScaleFactor; float num2 = (float)rowHeader.Top * this.ScaleFactor; float num3 = (float)columnHeader2.Right * this.ScaleFactor; float num4 = (float)rowHeader2.Bottom * this.ScaleFactor; float num5 = num3 - num; float num6 = num4 - num2; return new Rect(ref num, ref num2, ref num5, ref num6); } public override IView FocusView { get { return base.FocusView; } set { base.FocusView = value; bool flag = value == null; if (flag) { base.FocusView = this.rightBottomViewport; } } } protected virtual void UpdateVisibleRegion() { this.UpdateViewportVisibleRegion(this.rightBottomViewport, NormalViewportController.GetVisibleRegion(this.rightBottomViewport)); CellPosition freezePos = this.worksheet.FreezePos; bool flag = freezePos.Row > 0 || freezePos.Col > 0; if (flag) { this.UpdateViewportVisibleRegion(this.topLeftViewport, NormalViewportController.GetVisibleRegion(this.topLeftViewport)); this.UpdateViewportVisibleRegion(this.leftBottomViewport, new GridRegion(this.rightBottomViewport.VisibleRegion.startRow, this.topLeftViewport.VisibleRegion.startCol, this.rightBottomViewport.VisibleRegion.endRow, this.topLeftViewport.VisibleRegion.endCol)); this.UpdateViewportVisibleRegion(this.rightTopViewport, new GridRegion(this.topLeftViewport.VisibleRegion.startRow, this.rightBottomViewport.VisibleRegion.startCol, this.topLeftViewport.VisibleRegion.endRow, this.rightBottomViewport.VisibleRegion.endCol)); } bool flag2 = this.topLeftViewport != null; if (flag2) { this.colHeaderPart1.VisibleRegion = this.topLeftViewport.VisibleRegion; this.rowHeaderPart1.VisibleRegion = this.topLeftViewport.VisibleRegion; } this.colHeaderPart2.VisibleRegion = this.rightBottomViewport.VisibleRegion; this.rowHeaderPart2.VisibleRegion = this.rightBottomViewport.VisibleRegion; } private void UpdateViewportVisibleRegion(Viewport viewport, GridRegion range) { GridRegion visibleRegion = viewport.VisibleRegion; viewport.VisibleRegion = range; this.UpdateNewVisibleRegionTexts(viewport.VisibleRegion, visibleRegion); } private void UpdateNewVisibleRegionTexts(GridRegion region, GridRegion oldVisibleRegion) { Stopwatch stopwatch = Stopwatch.StartNew(); this.worksheet.cells.Iterate(region.startRow, region.startCol, region.Rows, region.Cols, true, delegate(int r, int c, Cell cell) { RowHeader rowHeader = this.worksheet.rows[r]; bool flag2 = rowHeader.InnerHeight <= 0; int result; if (flag2) { result = region.Cols; } else { int colspan = (int)cell.Colspan; bool flag3 = colspan <= 0; if (flag3) { result = 1; } else { bool flag4 = cell.RenderScaleFactor != this.ScaleFactor && !string.IsNullOrEmpty(cell.DisplayText); if (flag4) { this.worksheet.UpdateCellFont(cell, UpdateFontReason.ScaleChanged); cell.RenderScaleFactor = this.ScaleFactor; } result = ((colspan <= 0) ? 1 : colspan); } } return result; }); stopwatch.Stop(); long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; bool flag = elapsedMilliseconds > 10L; if (flag) { Debug.WriteLine("update new visible region text takes " + elapsedMilliseconds.ToString() + " ms."); } } internal static GridRegion GetVisibleRegion(Viewport viewport) { Stopwatch stopwatch = Stopwatch.StartNew(); Worksheet sheet = viewport.Worksheet; float renderScaleFactor = sheet.renderScaleFactor; GridRegion region = GridRegion.Empty; float scaledViewLeft = viewport.ScrollViewLeft; float scaledViewTop = viewport.ScrollViewTop; float scaledViewRight = viewport.ScrollViewLeft + viewport.Width / renderScaleFactor; float scaledViewBottom = viewport.ScrollViewTop + viewport.Height / renderScaleFactor; bool flag = viewport.Height > 0f && sheet.rows.Count > 0; if (flag) { float num = (float)sheet.rows.Last().Bottom; bool flag2 = scaledViewTop > num; if (flag2) { region.startRow = sheet.RowCount - 1; } else { int split = sheet.rows.Count / 2; ArrayHelper.QuickFind(split, 0, sheet.rows.Count, delegate(int rindex) { RowHeader rowHeader = sheet.rows[rindex]; float num3 = (float)rowHeader.Top; float num4 = (float)rowHeader.Bottom; bool flag9 = scaledViewTop >= num3 && scaledViewTop <= num4; int result; if (flag9) { region.startRow = rindex; result = 0; } else { bool flag10 = scaledViewTop < num3; if (flag10) { result = -1; } else { bool flag11 = scaledViewTop > num4; if (!flag11) { throw new InvalidOperationException(); } result = 1; } } return result; }); } bool flag3 = scaledViewBottom > num; if (flag3) { region.endRow = sheet.rows.Count - 1; } else { int split2 = sheet.rows.Count / 2; ArrayHelper.QuickFind(split2, 0, sheet.rows.Count, delegate(int rindex) { RowHeader rowHeader = sheet.rows[rindex]; float num3 = (float)rowHeader.Top; float num4 = (float)rowHeader.Bottom; bool flag9 = scaledViewBottom >= num3 && scaledViewBottom <= num4; int result; if (flag9) { region.endRow = rindex; result = 0; } else { bool flag10 = scaledViewBottom < num3; if (flag10) { result = -1; } else { bool flag11 = scaledViewBottom > num4; if (!flag11) { throw new InvalidOperationException(); } result = 1; } } return result; }); } } bool flag4 = viewport.Width > 0f && sheet.cols.Count > 0; if (flag4) { float num2 = (float)sheet.cols.Last().Right; bool flag5 = scaledViewLeft > num2; if (flag5) { region.startCol = sheet.cols.Count - 1; } else { int split3 = sheet.cols.Count / 2; ArrayHelper.QuickFind(split3, 0, sheet.cols.Count, delegate(int cindex) { ColumnHeader columnHeader = sheet.cols[cindex]; float num3 = (float)columnHeader.Left; float num4 = (float)columnHeader.Right; bool flag9 = scaledViewLeft >= num3 && scaledViewLeft <= num4; int result; if (flag9) { region.startCol = cindex; result = 0; } else { bool flag10 = scaledViewLeft < num3; if (flag10) { result = -1; } else { bool flag11 = scaledViewLeft > num4; if (!flag11) { throw new InvalidOperationException(); } result = 1; } } return result; }); } bool flag6 = scaledViewRight > num2; if (flag6) { region.endCol = sheet.cols.Count - 1; } else { int split4 = sheet.cols.Count / 2; ArrayHelper.QuickFind(split4, 0, sheet.cols.Count, delegate(int cindex) { ColumnHeader columnHeader = sheet.cols[cindex]; float num3 = (float)columnHeader.Left; float num4 = (float)columnHeader.Right; bool flag9 = scaledViewRight >= num3 && scaledViewRight <= num4; int result; if (flag9) { region.endCol = cindex; result = 0; } else { bool flag10 = scaledViewRight < num3; if (flag10) { result = -1; } else { bool flag11 = scaledViewRight > num4; if (!flag11) { throw new InvalidOperationException(); } result = 1; } } return result; }); } } Debug.Assert(region.endRow >= region.startRow); Debug.Assert(region.endCol >= region.startCol); stopwatch.Stop(); bool flag7 = region.Rows > 200 || region.Cols > 200; if (flag7) { Debug.WriteLine(string.Format("unusual visible region detected: [row: {0} - {1}, col: {2} - {3}]: {4} ms.", new object[] { region.startRow, region.endRow, region.startCol, region.endCol, stopwatch.ElapsedMilliseconds })); } bool flag8 = stopwatch.ElapsedMilliseconds > 15L; if (flag8) { Debug.WriteLine("update visible region takes " + stopwatch.ElapsedMilliseconds.ToString() + " ms."); } return region; } public override void UpdateController() { Stopwatch stopwatch = Stopwatch.StartNew(); bool flag = base.IsViewVisible(ViewTypes.ColOutline); bool flag2 = base.IsViewVisible(ViewTypes.RowOutline); bool flag3 = base.IsViewVisible(ViewTypes.ColumnHeader); bool flag4 = base.IsViewVisible(ViewTypes.RowHeader); bool flag5 = base.IsViewVisible(ViewTypes.LeadHeader); CellPosition freezePos = this.worksheet.FreezePos; bool flag6 = freezePos.Row > 0 || freezePos.Col > 0; float num = base.Bounds.X; float num2 = base.Bounds.Y; float num3 = 0f; float num4 = 0f; Rect bounds = new Rect(ref num, ref num2, ref num3, ref num4); num = 0f; num2 = 0f; num3 = 0f; num4 = 0f; Rect bounds2 = new Rect(ref num, ref num2, ref num3, ref num4); num = 0f; num2 = 0f; num3 = 0f; num4 = 0f; Rect rect = new Rect(ref num, ref num2, ref num3, ref num4); float scaleFactor = this.ScaleFactor; bool flag7 = flag3; if (flag7) { bounds2.Height = (float)((int)Math.Round((double)((float)this.worksheet.colHeaderHeight * scaleFactor))); } bool flag8 = flag4; if (flag8) { bounds2.Width = (float)((int)Math.Round((double)((float)this.worksheet.rowHeaderWidth * scaleFactor))); } float num5 = 16f * Math.Min(scaleFactor, 1f); bool flag9 = flag; if (flag9) { OutlineCollection outlineCollection = this.worksheet.outlines[RowOrColumn.Column]; bool flag10 = outlineCollection != null; if (flag10) { bounds.Height = (float)((int)Math.Round((double)((float)outlineCollection.Count * num5))); } else { flag = false; } } bool flag11 = flag2; if (flag11) { OutlineCollection outlineCollection2 = this.worksheet.outlines[RowOrColumn.Row]; bool flag12 = outlineCollection2 != null; if (flag12) { bounds.Width = (float)((int)Math.Round((double)((float)outlineCollection2.Count * num5))); } else { flag2 = false; } } bounds2.X = this.view.Left + bounds.Width; bounds2.Y = this.view.Top + bounds.Height; bool flag13 = flag5; if (flag13) { this.leadHeadPart.Bounds = bounds2; } float num6 = this.view.Right - bounds2.Right; float num7 = this.view.Bottom - bounds2.Bottom; bool flag14 = num6 < 0f; if (flag14) { num6 = 0f; } bool flag15 = num7 < 0f; if (flag15) { num7 = 0f; } num = bounds2.Right; num2 = bounds2.Bottom; rect = new Rect(ref num, ref num2, ref num6, ref num7); bool flag16 = flag; if (flag16) { bool flag17 = flag4; if (flag17) { View view = this.colOutlineHeadPart; num = bounds2.X; num2 = bounds.Y; num3 = bounds2.Width; num4 = bounds.Height; view.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); } View view2 = this.colOutlinePart2; num = bounds2.Right; num2 = bounds.Y; num3 = rect.Width; num4 = bounds.Height; view2.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); } bool flag18 = flag2; if (flag18) { bool flag19 = flag3; if (flag19) { View view3 = this.rowOutlineHeadPart; num = bounds.X; num2 = bounds.Bottom; num3 = bounds.Width; num4 = bounds2.Height; view3.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); } } num = 0f; num2 = 0f; num3 = 0f; num4 = 0f; Rect bounds3 = new Rect(ref num, ref num2, ref num3, ref num4); bool flag20 = flag6; if (flag20) { num = 0f; num2 = 0f; Point point = new Point(ref num, ref num2); num = 0f; num2 = 0f; num3 = 0f; num4 = 0f; Rect bounds4 = new Rect(ref num, ref num2, ref num3, ref num4); switch (this.worksheet.FreezeArea) { default: { Rect gridScaleBounds = this.GetGridScaleBounds(freezePos); num = rect.X + gridScaleBounds.X; num2 = rect.Y + gridScaleBounds.Y; point = new Point(ref num, ref num2); break; } case FreezeArea.LeftBottom: { Rect rangeScaledBounds = this.GetRangeScaledBounds(new GridRegion(freezePos.Row, freezePos.Col, this.worksheet.RowCount - 1, this.worksheet.ColumnCount - 1)); num = rect.X + rangeScaledBounds.X; num2 = rect.Bottom - rangeScaledBounds.Height; point = new Point(ref num, ref num2); break; } case FreezeArea.RightTop: { Rect rangeScaledBounds = this.GetRangeScaledBounds(new GridRegion(freezePos.Row, freezePos.Col, this.worksheet.RowCount - 1, this.worksheet.ColumnCount - 1)); num = rect.Right - rangeScaledBounds.Width; num2 = rect.Y + rangeScaledBounds.Y; point = new Point(ref num, ref num2); break; } case FreezeArea.RightBottom: { Rect rangeScaledBounds = this.GetRangeScaledBounds(new GridRegion(freezePos.Row, freezePos.Col, this.worksheet.RowCount - 1, this.worksheet.ColumnCount - 1)); num = rect.Right - rangeScaledBounds.Width; num2 = rect.Bottom - rangeScaledBounds.Height; point = new Point(ref num, ref num2); break; } } bool flag21 = point.X < rect.X; if (flag21) { point.X = rect.X; } bool flag22 = point.Y < rect.Y; if (flag22) { point.Y = rect.Y; } bool flag23 = point.X > rect.Right; if (flag23) { point.X = rect.Right; } bool flag24 = point.Y > rect.Bottom; if (flag24) { point.Y = rect.Bottom; } num = rect.X; num2 = rect.Y; num3 = point.X - rect.X; num4 = point.Y - rect.Y; bounds4 = new Rect(ref num, ref num2, ref num3, ref num4); num = bounds4.Right; num2 = bounds4.Bottom; num3 = rect.Width - bounds4.Width; num4 = rect.Height - bounds4.Height; bounds3 = new Rect(ref num, ref num2, ref num3, ref num4); this.topLeftViewport.Bounds = bounds4; View view4 = this.leftBottomViewport; num = bounds4.X; num2 = bounds3.Y; num3 = bounds4.Width; num4 = bounds3.Height; view4.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); View view5 = this.rightTopViewport; num = bounds3.X; num2 = bounds4.Y; num3 = bounds3.Width; num4 = bounds4.Height; view5.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); View view6 = this.colHeaderPart1; num = this.topLeftViewport.Left; num2 = this.leadHeadPart.Top; num3 = this.topLeftViewport.Width; num4 = (float)this.worksheet.colHeaderHeight * scaleFactor; view6.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); View view7 = this.rowHeaderPart1; num = this.leadHeadPart.Left; num2 = this.topLeftViewport.Top; num3 = (float)this.worksheet.rowHeaderWidth * scaleFactor; num4 = this.topLeftViewport.Height; view7.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); this.CreateOutlineHeaderViewIfNotExist(); bool flag25 = flag; if (flag25) { View view8 = this.colOutlinePart1; num = bounds4.X; num2 = bounds.Y; num3 = bounds4.Width; num4 = bounds.Height; view8.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); } bool flag26 = flag2; if (flag26) { View view9 = this.rowOutlinePart1; num = bounds.X; num2 = bounds4.Y; num3 = bounds.Width; num4 = bounds4.Height; view9.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); } } else { bounds3 = rect; } this.rightBottomViewport.Bounds = bounds3; View view10 = this.colHeaderPart2; num = bounds3.X; num2 = bounds2.Y; num3 = bounds3.Width; num4 = bounds2.Height; view10.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); View view11 = this.rowHeaderPart2; num = bounds2.X; num2 = bounds3.Y; num3 = bounds2.Width; num4 = bounds3.Height; view11.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); bool flag27 = flag2; if (flag27) { View view12 = this.rowOutlinePart2; num = bounds.X; num2 = bounds3.Y; num3 = bounds.Width; num4 = bounds3.Height; view12.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); } bool flag28 = flag; if (flag28) { View view13 = this.colOutlinePart2; num = bounds3.X; num2 = bounds.Y; num3 = bounds3.Width; num4 = bounds.Height; view13.Bounds = new Rect(ref num, ref num2, ref num3, ref num4); } bool flag29 = flag2 && flag; if (flag29) { this.outlineLeftTopSpace.Bounds = bounds; } IScrollableControlAdapter controlAdapter = this.worksheet.controlAdapter; num = (this.scrollHorLarge = this.view.Width); controlAdapter.ScrollBarHorizontalLargeChange = num; IScrollableControlAdapter controlAdapter2 = this.worksheet.controlAdapter; num = (this.scrollVerLarge = this.view.Height); controlAdapter2.ScrollBarVerticalLargeChange = num; this.UpdateVisibleRegion(); this.UpdateScrollBarSize(); IView view14 = this.View; bool flag30 = ((view14 != null) ? view14.Children : null) != null; if (flag30) { foreach (IView view15 in this.View.Children) { view15.ScaleFactor = this.View.ScaleFactor; } } this.view.UpdateView(); this.worksheet.RequestInvalidate(); stopwatch.Stop(); long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; bool flag31 = elapsedMilliseconds > 0L; if (flag31) { Debug.WriteLine("update viewport bounds done: " + elapsedMilliseconds.ToString() + " ms."); } } public override void Reset() { IViewport viewport = this.view as IViewport; bool flag = viewport != null; if (flag) { IViewport viewport2 = viewport; float num = 0f; float num2 = 0f; viewport2.ViewStart = new Point(ref num, ref num2); viewport.ScrollX = 0f; viewport.ScrollY = 0f; } this.view.UpdateView(); this.mainVisibleRegion = GridRegion.Empty; this.frozenVisibleRegion = GridRegion.Empty; IControlAdapter controlAdapter = this.worksheet.controlAdapter; controlAdapter.ScrollBarHorizontalMinimum = 0f; controlAdapter.ScrollBarVerticalMinimum = 0f; controlAdapter.ScrollBarHorizontalValue = 0f; controlAdapter.ScrollBarVerticalValue = 0f; } public void HorizontalScroll(float value) { this.ScrollViews(ScrollDirection.Horizontal, value, -1f); } public void VerticalScroll(float value) { this.ScrollViews(ScrollDirection.Vertical, -1f, value); } public virtual void ScrollOffsetViews(ScrollDirection dir, float offsetX, float offsetY) { this.ScrollViews(dir, ((dir & ScrollDirection.Horizontal) == ScrollDirection.Horizontal) ? (this.scrollHorValue + offsetX) : -1f, ((dir & ScrollDirection.Vertical) == ScrollDirection.Vertical) ? (this.scrollVerValue + offsetY) : -1f); this.SynchronizeScrollBar(); } public virtual void ScrollViews(ScrollDirection dir, float x, float y) { bool flag = float.IsNaN(x) || float.IsNaN(y); if (!flag) { bool flag2 = (dir & ScrollDirection.Horizontal) != ScrollDirection.Horizontal; if (flag2) { x = this.scrollHorValue; } bool flag3 = (dir & ScrollDirection.Vertical) != ScrollDirection.Vertical; if (flag3) { y = this.scrollVerValue; } bool flag4 = x == this.mainViewport.ScrollX && y == this.mainViewport.ScrollY; if (!flag4) { bool flag5 = x > this.scrollHorMax; if (flag5) { x = this.scrollHorMax; } else { bool flag6 = x < 0f; if (flag6) { x = 0f; } } bool flag7 = y > this.scrollVerMax; if (flag7) { y = this.scrollVerMax; } else { bool flag8 = y < 0f; if (flag8) { y = 0f; } } bool isEditing = this.worksheet.IsEditing; if (isEditing) { this.worksheet.EndEdit(EndEditReason.NormalFinish); } foreach (IView view in this.view.Children) { IViewport viewport = view as IViewport; bool flag9 = viewport != null; if (flag9) { viewport.ScrollTo(x, y); } } this.UpdateVisibleRegion(); this.view.UpdateView(); this.worksheet.RequestInvalidate(); this.scrollHorValue = this.mainViewport.ScrollX; this.scrollVerValue = this.mainViewport.ScrollY; Workbook workbook = this.worksheet.workbook; if (workbook != null) { workbook.RaiseWorksheetScrolledEvent(this.worksheet, x, y); } } } } public virtual void ScrollToRange(RangePosition range, CellPosition basePos) { Viewport viewport = this.FocusView as Viewport; bool flag = viewport != null; if (flag) { Rect scaledRangeBounds = this.worksheet.GetScaledRangeBounds(range); float scaleFactor = this.ScaleFactor; double num = (double)(viewport.ScrollViewTop * scaleFactor); double num2 = (double)(viewport.ScrollViewTop * scaleFactor + viewport.Height); double num3 = (double)(viewport.ScrollViewLeft * scaleFactor); double num4 = (double)(viewport.ScrollViewLeft * scaleFactor + viewport.Width); double num5 = 0.0; double num6 = 0.0; bool flag2 = scaledRangeBounds.Height < viewport.Height && (viewport.ScrollableDirections & ScrollDirection.Vertical) == ScrollDirection.Vertical; if (flag2) { bool flag3 = range.Rows < this.worksheet.rows.Count; if (flag3) { bool flag4 = (double)scaledRangeBounds.Y < num; if (flag4) { num6 = ((double)scaledRangeBounds.Y - num) / (double)this.ScaleFactor; } else { bool flag5 = (double)scaledRangeBounds.Bottom >= num2; if (flag5) { num6 = ((double)scaledRangeBounds.Bottom - num2) / (double)this.ScaleFactor + 1.0; } } } } bool flag6 = scaledRangeBounds.Width < viewport.Width && (viewport.ScrollableDirections & ScrollDirection.Horizontal) == ScrollDirection.Horizontal; if (flag6) { bool flag7 = range.Cols < this.worksheet.cols.Count; if (flag7) { bool flag8 = (double)scaledRangeBounds.X < num3; if (flag8) { num5 = ((double)scaledRangeBounds.X - num3) / (double)this.ScaleFactor; } else { bool flag9 = (double)scaledRangeBounds.Right >= num4; if (flag9) { num5 = ((double)scaledRangeBounds.Right - num4) / (double)this.ScaleFactor + 1.0; } } } } bool flag10 = num5 != 0.0 || num6 != 0.0; if (flag10) { this.ScrollOffsetViews(ScrollDirection.Both, (float)Math.Round(num5), (float)Math.Round(num6)); } } } private void UpdateScrollBarSize() { float scaleFactor = this.ScaleFactor; float num = 0f; float num2 = 0f; bool flag = this.worksheet.cols.Count > 0; if (flag) { num = (float)this.worksheet.cols[this.worksheet.cols.Count - 1].Right * scaleFactor + this.mainViewport.Left; num -= this.scrollHorLarge; } bool flag2 = this.worksheet.rows.Count > 0; if (flag2) { num2 = (float)this.worksheet.rows[this.worksheet.rows.Count - 1].Bottom * scaleFactor + this.mainViewport.Top; num2 -= this.scrollVerLarge; } int num3 = Math.Max(0, (int)Math.Ceiling((double)num)) + 1; int num4 = Math.Max(0, (int)Math.Ceiling((double)num2)) + 1; this.scrollHorMax = (float)num3; this.scrollVerMax = (float)num4; this.SynchronizeScrollBar(); } public void SynchronizeScrollBar() { bool flag = this.worksheet == null || this.worksheet.controlAdapter == null; if (!flag) { bool flag2 = this.scrollHorValue < this.scrollHorMin; if (flag2) { this.scrollHorValue = this.scrollHorMin; } else { bool flag3 = this.scrollHorValue > this.scrollHorMax; if (flag3) { this.scrollHorValue = this.scrollHorMax; } } bool flag4 = this.scrollVerValue < this.scrollVerMin; if (flag4) { this.scrollVerValue = this.scrollVerMin; } else { bool flag5 = this.scrollVerValue > this.scrollVerMax; if (flag5) { this.scrollVerValue = this.scrollVerMax; } } this.worksheet.controlAdapter.ScrollBarHorizontalMaximum = this.scrollHorMax; this.worksheet.controlAdapter.ScrollBarVerticalMaximum = this.scrollVerMax; this.worksheet.controlAdapter.ScrollBarHorizontalMinimum = this.scrollHorMin; this.worksheet.controlAdapter.ScrollBarVerticalMinimum = this.scrollVerMin; this.worksheet.controlAdapter.ScrollBarHorizontalLargeChange = this.scrollHorLarge; this.worksheet.controlAdapter.ScrollBarVerticalLargeChange = this.scrollVerLarge; this.worksheet.controlAdapter.ScrollBarHorizontalValue = this.scrollHorValue; this.worksheet.controlAdapter.ScrollBarVerticalValue = this.scrollVerValue; } } public void Freeze(CellPosition freezePos, FreezeArea area = FreezeArea.LeftTop) { Rect cellBounds = this.worksheet.GetCellBounds(freezePos); bool flag = freezePos == CellPosition.Zero; if (flag) { this.mainViewport = this.rightBottomViewport; Viewport viewport = this.rightBottomViewport; float num = 0f; float num2 = 0f; viewport.ViewStart = new Point(ref num, ref num2); this.rowHeaderPart2.ScrollableDirections = ScrollDirection.Vertical; this.colHeaderPart2.ScrollableDirections = ScrollDirection.Horizontal; bool flag2 = this.topLeftViewport != null; if (flag2) { this.topLeftViewport.Visible = (this.leftBottomViewport.Visible = (this.rightTopViewport.Visible = false)); } bool flag3 = this.rowHeaderPart1 != null; if (flag3) { this.rowHeaderPart1.Visible = false; } bool flag4 = this.colHeaderPart1 != null; if (flag4) { this.colHeaderPart1.Visible = false; } bool flag5 = this.rowOutlinePart1 != null; if (flag5) { this.rowOutlinePart1.Visible = false; } bool flag6 = this.colOutlinePart1 != null; if (flag6) { this.colOutlinePart1.Visible = false; } } else { bool flag7 = this.rightTopViewport == null; if (flag7) { this.AddView(this.rightTopViewport = new SheetViewport(this)); } bool flag8 = this.leftBottomViewport == null; if (flag8) { this.AddView(this.leftBottomViewport = new SheetViewport(this)); } bool flag9 = this.colHeaderPart1 == null; if (flag9) { this.AddView(this.colHeaderPart1 = new ColumnHeaderView(this)); } bool flag10 = this.rowHeaderPart1 == null; if (flag10) { this.AddView(this.rowHeaderPart1 = new RowHeaderView(this)); } this.CreateOutlineHeaderViewIfNotExist(); bool flag11 = this.topLeftViewport == null; if (flag11) { this.AddView(this.topLeftViewport = new SheetViewport(this)); } Viewport viewport2 = this.topLeftViewport; float num = 0f; float num2 = 0f; viewport2.ViewStart = new Point(ref num, ref num2); Viewport viewport3 = this.leftBottomViewport; num = 0f; num2 = cellBounds.Y; viewport3.ViewStart = new Point(ref num, ref num2); Viewport viewport4 = this.rightTopViewport; num = cellBounds.X; num2 = 0f; viewport4.ViewStart = new Point(ref num, ref num2); Viewport viewport5 = this.rightBottomViewport; num = cellBounds.X; num2 = cellBounds.Y; viewport5.ViewStart = new Point(ref num, ref num2); switch (this.worksheet.FreezeArea) { default: this.topLeftViewport.ScrollableDirections = ScrollDirection.None; this.leftBottomViewport.ScrollableDirections = ScrollDirection.Vertical; this.rightTopViewport.ScrollableDirections = ScrollDirection.Horizontal; this.colHeaderPart1.ScrollableDirections = ScrollDirection.None; this.rowHeaderPart1.ScrollableDirections = ScrollDirection.None; this.colHeaderPart2.ScrollableDirections = ScrollDirection.Horizontal; this.rowHeaderPart2.ScrollableDirections = ScrollDirection.Vertical; this.mainViewport = this.rightBottomViewport; break; case FreezeArea.LeftBottom: this.topLeftViewport.ScrollableDirections = ScrollDirection.Vertical; this.leftBottomViewport.ScrollableDirections = ScrollDirection.None; this.rightBottomViewport.ScrollableDirections = ScrollDirection.Horizontal; this.colHeaderPart1.ScrollableDirections = ScrollDirection.None; this.rowHeaderPart1.ScrollableDirections = ScrollDirection.Vertical; this.colHeaderPart2.ScrollableDirections = ScrollDirection.Horizontal; this.rowHeaderPart2.ScrollableDirections = ScrollDirection.None; this.mainViewport = this.rightTopViewport; break; case FreezeArea.RightTop: this.topLeftViewport.ScrollableDirections = ScrollDirection.Horizontal; this.rightTopViewport.ScrollableDirections = ScrollDirection.None; this.rightBottomViewport.ScrollableDirections = ScrollDirection.Vertical; this.colHeaderPart1.ScrollableDirections = ScrollDirection.Horizontal; this.rowHeaderPart1.ScrollableDirections = ScrollDirection.None; this.colHeaderPart2.ScrollableDirections = ScrollDirection.None; this.rowHeaderPart2.ScrollableDirections = ScrollDirection.Vertical; this.mainViewport = this.leftBottomViewport; break; case FreezeArea.RightBottom: this.leftBottomViewport.ScrollableDirections = ScrollDirection.Horizontal; this.rightTopViewport.ScrollableDirections = ScrollDirection.Vertical; this.rightBottomViewport.ScrollableDirections = ScrollDirection.None; this.colHeaderPart1.ScrollableDirections = ScrollDirection.Horizontal; this.rowHeaderPart1.ScrollableDirections = ScrollDirection.Vertical; this.colHeaderPart2.ScrollableDirections = ScrollDirection.None; this.rowHeaderPart2.ScrollableDirections = ScrollDirection.None; this.mainViewport = this.topLeftViewport; break; } this.topLeftViewport.Visible = (this.leftBottomViewport.Visible = (this.rightTopViewport.Visible = true)); this.colHeaderPart1.Visible = this.colHeaderPart2.Visible; this.rowHeaderPart1.Visible = this.rowHeaderPart2.Visible; bool flag12 = this.colOutlinePart1 != null && this.colOutlinePart2 != null; if (flag12) { this.colOutlinePart1.Visible = this.colOutlinePart2.Visible; } bool flag13 = this.rowOutlinePart1 != null && this.rowOutlinePart2 != null; if (flag13) { this.rowOutlinePart1.Visible = this.rowOutlinePart2.Visible; } } this.mainViewport.ScrollableDirections = ScrollDirection.Both; bool flag14 = this.rowHeaderPart1 != null; if (flag14) { this.rowHeaderPart1.ViewTop = this.topLeftViewport.ViewTop; } bool flag15 = this.colHeaderPart1 != null; if (flag15) { this.colHeaderPart1.ViewLeft = this.topLeftViewport.ViewLeft; } this.colHeaderPart2.ViewLeft = this.rightBottomViewport.ViewLeft; this.rowHeaderPart2.ViewTop = this.rightBottomViewport.ViewTop; bool flag16 = this.colOutlinePart2 != null; if (flag16) { this.colOutlinePart2.ViewLeft = this.rightBottomViewport.ViewLeft; this.colOutlinePart2.ScrollableDirections = this.colHeaderPart2.ScrollableDirections; bool flag17 = this.colOutlinePart1 != null; if (flag17) { this.colOutlinePart1.ViewStart = this.colHeaderPart1.ViewStart; this.colOutlinePart1.ScrollableDirections = this.colHeaderPart1.ScrollableDirections; } } bool flag18 = this.rowOutlinePart2 != null; if (flag18) { this.rowOutlinePart2.ViewTop = this.rightBottomViewport.ViewTop; this.rowOutlinePart2.ScrollableDirections = this.rowHeaderPart2.ScrollableDirections; bool flag19 = this.rowOutlinePart1 != null; if (flag19) { this.rowOutlinePart1.ViewStart = this.rowHeaderPart1.ViewStart; this.rowOutlinePart1.ScrollableDirections = this.rowHeaderPart1.ScrollableDirections; } } this.worksheet.controlAdapter.ScrollBarHorizontalMinimum = 0f; this.worksheet.controlAdapter.ScrollBarVerticalMinimum = 0f; this.worksheet.controlAdapter.ScrollBarHorizontalLargeChange = (float)Math.Round((double)this.mainViewport.Width); this.worksheet.controlAdapter.ScrollBarVerticalLargeChange = (float)Math.Round((double)this.mainViewport.Height); this.currentFreezePos = freezePos; this.currentFrozenArea = area; this.UpdateController(); } private void CreateOutlineHeaderViewIfNotExist() { bool flag = this.rowOutlinePart1 == null && this.rowOutlinePart2 != null; if (flag) { this.AddView(this.rowOutlinePart1 = new RowOutlineView(this)); this.RemoveView(this.rowOutlineHeadPart); this.AddView(this.rowOutlineHeadPart); } bool flag2 = this.colOutlinePart1 == null && this.colOutlinePart2 != null; if (flag2) { this.AddView(this.colOutlinePart1 = new ColumnOutlinePart(this)); this.RemoveView(this.colOutlineHeadPart); this.AddView(this.colOutlineHeadPart); bool flag3 = this.outlineLeftTopSpace != null; if (flag3) { this.RemoveView(this.outlineLeftTopSpace); this.AddView(this.outlineLeftTopSpace); } } } public override void Draw(CellDrawingContext dc) { base.Draw(dc); IGraphics graphics = dc.Graphics; bool flag = this.view != null && this.worksheet.HasSettings(WorksheetSettings.View_ShowFrozenLine); if (flag) { CellPosition freezePos = this.worksheet.FreezePos; bool flag2 = freezePos.Col > 0; if (flag2) { graphics.DrawLine(this.leftBottomViewport.Right, this.view.Top, this.leftBottomViewport.Right, this.view.Bottom, Color.Gray); } bool flag3 = freezePos.Row > 0; if (flag3) { graphics.DrawLine(this.view.Left, this.rightTopViewport.Bottom, this.view.Right, this.rightTopViewport.Bottom, Color.Gray); } } } private LeadHeaderView leadHeadPart; private RowHeaderView rowHeaderPart1 = null; private RowHeaderView rowHeaderPart2 = null; private ColumnHeaderView colHeaderPart2 = null; private ColumnHeaderView colHeaderPart1 = null; private SheetViewport topLeftViewport = null; private SheetViewport leftBottomViewport = null; private SheetViewport rightBottomViewport = null; private SheetViewport rightTopViewport = null; internal SheetViewport mainViewport = null; private SpaceView rightBottomSpace; private GridRegion frozenVisibleRegion = GridRegion.Empty; private GridRegion mainVisibleRegion = GridRegion.Empty; private float scrollHorMin = 0f; private float scrollHorMax; private float scrollHorLarge; private float scrollHorValue; private float scrollVerMin = 0f; private float scrollVerMax; private float scrollVerLarge; private float scrollVerValue; private CellPosition currentFreezePos = new CellPosition(0, 0); private FreezeArea currentFrozenArea = FreezeArea.None; private RowOutlineView rowOutlinePart2; private RowOutlineView rowOutlinePart1; private RowOutlineHeaderView rowOutlineHeadPart; private ColumnOutlinePart colOutlinePart2; private ColumnOutlinePart colOutlinePart1; private ColumnOutlineHeadPart colOutlineHeadPart; private OutlineLeftTopSpace outlineLeftTopSpace; } }