using System; using CPF.Drawing; using CPF.Input; using CPF.ReoGrid.Actions; using CPF.ReoGrid.CellTypes; using CPF.ReoGrid.Drawing; using CPF.ReoGrid.Events; using CPF.ReoGrid.Graphics; using CPF.ReoGrid.Interaction; using CPF.ReoGrid.Main; using CPF.ReoGrid.Rendering; namespace CPF.ReoGrid.Views { internal class ColumnHeaderView : HeaderView { public ColumnHeaderView(IViewportController vc) : base(vc) { this.ScrollableDirections = ScrollDirection.Horizontal; } public override void DrawView(CellDrawingContext dc) { IRenderer renderer = dc.Renderer; IGraphics graphics = dc.Graphics; bool flag = this.bounds.Height <= 0f || this.sheet.controlAdapter == null; if (!flag) { ControlAppearanceStyle controlStyle = this.sheet.workbook.controlAdapter.ControlStyle; renderer.BeginDrawHeaderText(this.scaleFactor); CPFPen pen = renderer.GetPen(controlStyle.Colors[ControlAppearanceColors.RowHeadSplitter]); Brush brush = renderer.GetBrush(controlStyle.Colors[ControlAppearanceColors.ColHeadText]); bool flag2 = this.sheet.SelectionRange.Rows == this.sheet.RowCount; for (int i = this.visibleRegion.startCol; i <= this.visibleRegion.endCol; i++) { bool flag3 = i >= this.sheet.SelectionRange.Col && i <= this.sheet.SelectionRange.EndCol; ColumnHeader columnHeader = this.sheet.cols[i]; float num = (float)columnHeader.Left * this.scaleFactor; float num2 = (float)columnHeader.InnerWidth * this.scaleFactor; bool flag4 = !columnHeader.IsVisible; if (flag4) { graphics.DrawLine(pen, num - 1f, 0f, num - 1f, this.bounds.Bottom); } else { float num3 = 0f; float height = this.bounds.Height; Rect rect = new Rect(ref num, ref num3, ref num2, ref height); graphics.FillRectangleLinear(controlStyle.GetColHeadStartColor(false, flag3, flag3 && flag2, false), controlStyle.GetColHeadEndColor(false, flag3, flag3 && flag2, false), 90f, rect); graphics.DrawLine(pen, num, 0f, num, this.bounds.Height); Brush brush2 = (columnHeader.TextColor != null) ? dc.Renderer.GetBrush(columnHeader.TextColor.Value) : brush; bool flag5 = brush2 == null; if (flag5) { brush2 = brush; } renderer.DrawHeaderText(columnHeader.RenderText, brush2, rect); bool flag6 = columnHeader.Body != null; if (flag6) { graphics.PushTransform(); graphics.TranslateTransform(rect.X, rect.Y); columnHeader.Body.OnPaint(dc, rect.Size); graphics.PopTransform(); } } } float num4 = (float)this.sheet.cols[this.visibleRegion.endCol].Right * this.scaleFactor; graphics.DrawLine(pen, num4, 0f, num4, this.bounds.Height); } } public override bool OnMouseDown(Point location, MouseButtons buttons, InputModifiers modifiers) { bool flag = false; OperationStatus operationStatus = this.sheet.operationStatus; OperationStatus operationStatus2 = operationStatus; if (operationStatus2 == OperationStatus.Default) { int num = -1; bool flag2 = this.sheet.FindColumnByPosition(location.X, out num); bool flag3 = num >= 0; if (flag3) { bool flag4 = flag2 && buttons == MouseButtons.Left && this.sheet.HasSettings(WorksheetSettings.Edit_AllowAdjustColumnWidth); if (flag4) { this.sheet.currentColWidthChanging = num; this.sheet.operationStatus = OperationStatus.AdjustColumnWidth; this.sheet.controlAdapter.ChangeCursor(CursorStyle.ChangeColumnWidth); this.sheet.RequestInvalidate(); float headerAdjustBackup = this.sheet.headerAdjustNewValue = (float)this.sheet.cols[this.sheet.currentColWidthChanging].InnerWidth; this.headerAdjustBackup = headerAdjustBackup; this.SetFocus(); flag = true; } bool flag5 = !flag; if (flag5) { ColumnHeader columnHeader = this.sheet.cols[num]; bool flag6 = columnHeader.Body != null; if (flag6) { Worksheet sheet = this.sheet; float headerAdjustBackup = (location.X - (float)columnHeader.Left) * this.scaleFactor; float num2 = location.Y / this.scaleFactor; Point relativePosition = new Point(ref headerAdjustBackup, ref num2); float num3 = (location.X - (float)columnHeader.Left) * this.scaleFactor + this.Left; float num4 = location.Y / this.scaleFactor; WorksheetMouseEventArgs e = new WorksheetMouseEventArgs(sheet, relativePosition, new Point(ref num3, ref num4), buttons, 1); IHeaderBody body = columnHeader.Body; headerAdjustBackup = (float)columnHeader.InnerWidth * this.scaleFactor; num2 = (float)this.sheet.colHeaderHeight; flag = body.OnMouseDown(new Size(ref headerAdjustBackup, ref num2), e); } } bool flag7 = !flag && this.sheet.selectionMode > WorksheetSelectionMode.None; if (flag7) { bool flag8 = this.sheet.selectionMode == WorksheetSelectionMode.Range && this.sheet.selectionRange.Rows == this.sheet.rows.Count && this.sheet.selectionRange.ContainsColumn(num); bool flag9 = !flag8 || buttons == MouseButtons.Left; if (flag9) { this.sheet.operationStatus = OperationStatus.FullColumnSelect; this.sheet.controlAdapter.ChangeCursor(CursorStyle.FullColumnSelect); this.SetFocus(); this.sheet.SelectRangeStartByMouse(this.PointToController(location), modifiers); flag = true; } } bool flag10 = buttons == MouseButtons.Right; if (flag10) { this.sheet.ControlAdapter.ShowContextMenuStrip(ViewTypes.ColumnHeader, this.PointToController(location)); } } } return flag; } public override bool OnMouseMove(Point location, MouseButtons buttons) { bool result = false; OperationStatus operationStatus = this.sheet.operationStatus; OperationStatus operationStatus2 = operationStatus; if (operationStatus2 != OperationStatus.Default) { switch (operationStatus2) { case OperationStatus.FullColumnSelect: case OperationStatus.FullSingleColumnSelect: { bool flag = buttons == MouseButtons.Left; if (flag) { this.sheet.controlAdapter.ChangeCursor(CursorStyle.FullColumnSelect); this.sheet.SelectRangeEndByMouse(this.PointToController(location)); result = true; } break; } case OperationStatus.AdjustColumnWidth: { bool flag2 = this.sheet.currentColWidthChanging >= 0 && buttons == MouseButtons.Left; if (flag2) { ColumnHeader columnHeader = this.sheet.cols[this.sheet.currentColWidthChanging]; this.sheet.headerAdjustNewValue = location.X - (float)columnHeader.Left; bool flag3 = this.sheet.headerAdjustNewValue < 0f; if (flag3) { this.sheet.headerAdjustNewValue = 0f; } this.sheet.controlAdapter.ChangeCursor(CursorStyle.ChangeColumnWidth); this.sheet.RequestInvalidate(); result = true; } break; } } } else { bool flag4 = this.sheet.currentColWidthChanging == -1 && this.sheet.currentRowHeightChanging == -1; if (flag4) { int num = -1; bool flag5 = this.sheet.FindColumnByPosition(location.X, out num) && this.sheet.HasSettings(WorksheetSettings.Edit_AllowAdjustColumnWidth); bool flag6 = num >= 0; if (flag6) { CursorStyle cursorStyle = flag5 ? CursorStyle.ChangeColumnWidth : ((this.sheet.selectionMode == WorksheetSelectionMode.None) ? CursorStyle.Selection : CursorStyle.FullColumnSelect); ColumnHeader columnHeader2 = this.sheet.cols[num]; bool flag7 = columnHeader2.Body != null; if (flag7) { Worksheet sheet = this.sheet; float num2 = (location.X - (float)columnHeader2.Left) * this.scaleFactor; float num3 = location.Y / this.scaleFactor; WorksheetMouseEventArgs worksheetMouseEventArgs = new WorksheetMouseEventArgs(sheet, new Point(ref num2, ref num3), location, buttons, 1) { CursorStyle = cursorStyle }; IHeaderBody body = columnHeader2.Body; num2 = (float)columnHeader2.InnerWidth * this.scaleFactor; num3 = (float)this.sheet.colHeaderHeight; result = body.OnMouseMove(new Size(ref num2, ref num3), worksheetMouseEventArgs); cursorStyle = worksheetMouseEventArgs.CursorStyle; } this.sheet.controlAdapter.ChangeCursor(cursorStyle); } } } return result; } public override bool OnMouseUp(Point location, MouseButtons buttons, InputModifiers modifiers) { OperationStatus operationStatus = this.sheet.operationStatus; OperationStatus operationStatus2 = operationStatus; bool result; if (operationStatus2 != OperationStatus.FullColumnSelect) { if (operationStatus2 != OperationStatus.AdjustColumnWidth) { result = false; } else { bool flag = this.sheet.currentColWidthChanging > -1; if (flag) { bool flag2 = this.sheet.selectionMode == WorksheetSelectionMode.Range && this.sheet.selectionRange.Rows == this.sheet.rows.Count && this.sheet.selectionRange.ContainsColumn(this.sheet.currentColWidthChanging); ushort num = (ushort)this.sheet.headerAdjustNewValue; bool flag3 = (float)num != this.headerAdjustBackup; if (flag3) { bool flag4 = flag2; SetColumnsWidthAction action; if (flag4) { action = new SetColumnsWidthAction(this.sheet.selectionRange.Col, this.sheet.selectionRange.Cols, num); } else { action = new SetColumnsWidthAction(this.sheet.currentColWidthChanging, 1, num); } this.sheet.DoAction(action); } } this.sheet.currentColWidthChanging = -1; this.sheet.operationStatus = OperationStatus.Default; this.sheet.RequestInvalidate(); this.headerAdjustBackup = (this.sheet.headerAdjustNewValue = 0f); this.FreeFocus(); result = true; } } else { this.sheet.operationStatus = OperationStatus.Default; this.sheet.ControlAdapter.ChangeCursor(CursorStyle.Selection); this.FreeFocus(); result = true; } return result; } public override bool OnMouseDoubleClick(Point location, MouseButtons buttons) { int num = -1; bool flag = this.sheet.FindColumnByPosition(location.X, out num); bool flag2 = num >= 0; if (flag2) { bool flag3 = flag && buttons == MouseButtons.Left && this.sheet.HasSettings(WorksheetSettings.Edit_AllowAdjustColumnWidth); if (flag3) { this.sheet.AutoFitColumnWidth(num, true); return true; } } return false; } public static Rect GetColHeaderBounds(Worksheet sheet, int col, Point position) { bool flag = sheet == null; if (flag) { throw new ArgumentNullException("sheet"); } IViewportController viewportController = sheet.ViewportController; bool flag2 = viewportController == null || viewportController.View == null; if (flag2) { throw new ArgumentNullException("viewportController"); } IViewport viewport = viewportController.View.GetViewByPoint(position) as ColumnHeaderView; bool flag3 = viewport == null; if (flag3) { throw new ArgumentNullException("Cannot found column header view from specified position"); } bool flag4 = viewport is ColumnHeaderView; Rect result; if (flag4) { ColumnHeader columnHeader = sheet.RetrieveColumnHeader(col); float renderScaleFactor = sheet.renderScaleFactor; float num = (float)columnHeader.Left * renderScaleFactor + viewport.Left - viewport.ScrollViewLeft; float num2 = viewport.Top - viewport.ScrollViewTop; float num3 = (float)columnHeader.InnerWidth * renderScaleFactor; float num4 = (float)sheet.colHeaderHeight * renderScaleFactor; result = new Rect(ref num, ref num2, ref num3, ref num4); } else { result = default(Rect); } return result; } } }