using System; using System.Diagnostics; using CPF.Controls; using CPF.Drawing; using CPF.Input; using CPF.ReoGrid.Drawing; using CPF.ReoGrid.Main; using CPF.ReoGrid.Rendering; using CPF.Shapes; using CPF.Threading; namespace CPF.ReoGrid.WPF { internal class SheetTabControl : Grid, ISheetTabControl { public SheetTabControl() { base.Background = StaticResources.SystemColor_Control; this.BorderColor = StaticResources.DeepSkyBlue; base.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(20f) }); base.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(20f) }); base.ColumnDefinitions.Add(new ColumnDefinition()); base.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(30f) }); base.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(5f) }); ArrowBorder arrowBorder = new ArrowBorder(this); Polygon polygon = new Polygon(); Collection points = polygon.Points; float num = 6f; float num2 = 0f; points.Add(new Point(ref num, ref num2)); Collection points2 = polygon.Points; float num3 = 0f; float num4 = 5f; points2.Add(new Point(ref num3, ref num4)); Collection points3 = polygon.Points; float num5 = 6f; float num6 = 10f; points3.Add(new Point(ref num5, ref num6)); polygon.Fill = StaticResources.ControlDarkDarkBrush; polygon.IsAntiAlias = true; arrowBorder.Child = polygon; arrowBorder.Name = "left"; arrowBorder.BorderFill = null; arrowBorder.Background = StaticResources.SystemColor_Control; Border border = arrowBorder; ArrowBorder arrowBorder2 = new ArrowBorder(this); Polygon polygon2 = new Polygon(); Collection points4 = polygon2.Points; num = 0f; num2 = 0f; points4.Add(new Point(ref num, ref num2)); Collection points5 = polygon2.Points; num3 = 6f; num4 = 5f; points5.Add(new Point(ref num3, ref num4)); Collection points6 = polygon2.Points; num5 = 0f; num6 = 10f; points6.Add(new Point(ref num5, ref num6)); polygon2.Fill = StaticResources.ControlDarkDarkBrush; polygon2.IsAntiAlias = true; arrowBorder2.Child = polygon2; arrowBorder2.Name = "right"; arrowBorder2.BorderFill = null; arrowBorder2.Background = StaticResources.SystemColor_Control; Border border2 = arrowBorder2; Panel panel = new Panel { ClipToBounds = true, Name = "clipPanel", MarginLeft = 0, MarginRight = 0, MarginTop = 0, MarginBottom = 0, Children = { this.canvas } }; this.Children.Add(panel); Grid.ColumnIndex(panel, 2); this.Children.Add(border); Grid.ColumnIndex(border, 0); this.Children.Add(border2); Grid.ColumnIndex(border2, 1); this.newSheetImage = new Picture { Source = "res://CPF.ReoGrid/Resources/NewBuildDefinition_8952_inactive.png", Cursor = Cursors.Hand, Name = "new" }; this.newSheetImage.MouseEnter += delegate(object s, CPF.Input.MouseEventArgs e) { (s as Picture).Source = "res://CPF.ReoGrid/Resources/NewBuildDefinition_8952.png"; }; this.newSheetImage.MouseLeave += delegate(object s, CPF.Input.MouseEventArgs e) { (s as Picture).Source = "res://CPF.ReoGrid/Resources/NewBuildDefinition_8952_inactive.png"; }; this.newSheetImage["MouseDown"] = new CommandDescribe(delegate(CpfObject s, object e) { bool flag = this.NewSheetClick != null; if (flag) { this.NewSheetClick(this, null); } }); this.Children.Add(this.newSheetImage); Grid.ColumnIndex(this.newSheetImage, 3); Border rightThumb = new Border { Child = new RightThumb(this), Cursor = Cursors.SizeWestEast, Background = StaticResources.SystemColor_Control, Height = "100%", BorderFill = null, Name = "rightThumb" }; this.Children.Add(rightThumb); Grid.ColumnIndex(rightThumb, 4); this.scrollTimer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 10) }; this.scrollTimer.Tick += delegate(object s, EventArgs e) { float num7 = this.canvas.MarginLeft.Value; bool flag = this.scrollLeftDown; if (flag) { bool flag2 = num7 < 0f; if (flag2) { num7 += 5f; bool flag3 = num7 > 0f; if (flag3) { num7 = 0f; } } } else { bool flag4 = this.scrollRightDown; if (flag4) { float num8 = base.ColumnDefinitions[2].ActualWidth - this.canvas.ActualSize.Width; bool flag5 = num7 > num8; if (flag5) { num7 -= 5f; bool flag6 = num7 < num8; if (flag6) { num7 = num8; } } } } bool flag7 = this.canvas.MarginLeft.Value != num7; if (flag7) { this.canvas.MarginLeft = num7; } }; border["MouseDown"] = new CommandDescribe(delegate(CpfObject s, object e) { this.scrollRightDown = false; MouseButtonEventArgs mouseButtonEventArgs = e as MouseButtonEventArgs; bool flag = mouseButtonEventArgs.LeftButton == MouseButtonState.Pressed; if (flag) { this.scrollLeftDown = true; this.scrollTimer.IsEnabled = true; } else { bool flag2 = mouseButtonEventArgs.RightButton == MouseButtonState.Pressed; if (flag2) { bool flag3 = this.SheetListClick != null; if (flag3) { this.SheetListClick(this, null); } } } }); border["MouseUp"] = new CommandDescribe(delegate(CpfObject s, object e) { this.scrollTimer.IsEnabled = false; this.scrollLeftDown = false; }); border2["MouseDown"] = new CommandDescribe(delegate(CpfObject s, object e) { this.scrollLeftDown = false; MouseButtonEventArgs mouseButtonEventArgs = e as MouseButtonEventArgs; bool flag = mouseButtonEventArgs.LeftButton == MouseButtonState.Pressed; if (flag) { this.scrollRightDown = true; this.scrollTimer.IsEnabled = true; } else { bool flag2 = mouseButtonEventArgs.RightButton == MouseButtonState.Pressed; if (flag2) { bool flag3 = this.SheetListClick != null; if (flag3) { this.SheetListClick(this, null); } } } }); border2["MouseUp"] = new CommandDescribe(delegate(CpfObject s, object e) { this.scrollTimer.IsEnabled = false; this.scrollRightDown = false; }); rightThumb["MouseDown"] = new CommandDescribe(delegate(CpfObject s, object e) { this.splitterMoving = true; rightThumb.CaptureMouse(); (e as CPF.Input.MouseEventArgs).Handled = true; }); rightThumb["MouseMove"] = new CommandDescribe(delegate(CpfObject s, object e) { bool flag = this.splitterMoving; if (flag) { bool flag2 = this.SplitterMoving != null; if (flag2) { this.SplitterMoving(this, null); } } }); rightThumb["MouseUp"] = new CommandDescribe(delegate(CpfObject s, object e) { this.splitterMoving = false; rightThumb.ReleaseMouseCapture(); }); } protected override void OnLayoutUpdated() { base.OnLayoutUpdated(); } public Color SelectedBackColor { get { return (Color)this.GetValue("SelectedBackColor"); } set { this.SetValue(value, "SelectedBackColor"); } } public Color SelectedTextColor { get { return (Color)this.GetValue("SelectedTextColor"); } set { this.SetValue(value, "SelectedTextColor"); } } public Color BorderColor { get { return (Color)this.GetValue("BorderColor"); } set { this.SetValue(value, "BorderColor"); } } public int SelectedIndex { get { return (int)this.GetValue("SelectedIndex"); } set { this.SetValue(value, "SelectedIndex"); } } [PropertyChanged("SelectedIndex")] private void OnSelectedIndex(object newValue, object oldValue, PropertyMetadataAttribute attribute) { Grid grid = this.canvas; int num = (int)oldValue; bool flag = num >= 0 && num < grid.Children.Count; if (flag) { SheetTabItem sheetTabItem = grid.Children[num] as SheetTabItem; bool flag2 = sheetTabItem != null; if (flag2) { sheetTabItem.IsSelected = false; } } num = (int)newValue; bool flag3 = num >= 0 && num < grid.Children.Count; if (flag3) { SheetTabItem sheetTabItem2 = grid.Children[num] as SheetTabItem; bool flag4 = sheetTabItem2 != null; if (flag4) { sheetTabItem2.IsSelected = true; } } bool flag5 = this.SelectedIndexChanged != null; if (flag5) { this.SelectedIndexChanged(this, null); } } [NotCpfProperty] public bool NewButtonVisible { get { return this.newSheetImage.Visibility == Visibility.Visible; } set { this.newSheetImage.Visibility = (value ? Visibility.Visible : Visibility.Hidden); } } [NotCpfProperty] public bool AllowDragToMove { get; set; } public void AddTab(string title) { int count = this.canvas.Children.Count; this.InsertTab(count, title); } public void InsertTab(int index, string title) { SheetTabItem sheetTabItem = new SheetTabItem(this, title) { Height = "100%" }; this.canvas.ColumnDefinitions.Add(new ColumnDefinition { Width = "Auto" }); this.canvas.Children.Add(sheetTabItem); Grid.ColumnIndex(sheetTabItem, index); sheetTabItem.MouseDown += this.Tab_MouseDown; bool flag = this.canvas.Children.Count == 1; if (flag) { sheetTabItem.IsSelected = true; } } private void Tab_MouseDown(object sender, MouseButtonEventArgs e) { int num = this.canvas.Children.IndexOf((UIElement)sender); SheetTabMouseEventArgs sheetTabMouseEventArgs = new SheetTabMouseEventArgs { Handled = false, Location = MouseDevice.GetPosition(this), Index = num, MouseButtons = WPFUtility.ConvertToUIMouseButtons(e) }; bool flag = this.TabMouseDown != null; if (flag) { this.TabMouseDown(this, sheetTabMouseEventArgs); } bool flag2 = !sheetTabMouseEventArgs.Handled; if (flag2) { this.SelectedIndex = num; } } public void RemoveTab(int index) { SheetTabItem sheetTabItem = (SheetTabItem)this.canvas.Children[index]; this.canvas.Children.RemoveAt(index); this.canvas.ColumnDefinitions.RemoveAt(index); for (int i = index; i < this.canvas.Children.Count; i++) { Grid.ColumnIndex(this.canvas.Children[i], i); } } public void UpdateTab(int index, string title, Color backColor, Color textColor) { SheetTabItem sheetTabItem = this.canvas.Children[index] as SheetTabItem; bool flag = sheetTabItem != null; if (flag) { sheetTabItem.ChangeTitle(title); this.canvas.ColumnDefinitions[index].Width = new GridLength(sheetTabItem.Width.Value + 1f); sheetTabItem.BackColor = backColor; sheetTabItem.TextColor = textColor; } } public void ClearTabs() { this.canvas.Children.Clear(); this.canvas.ColumnDefinitions.Clear(); } public int TabCount { get { return this.canvas.Children.Count; } } protected override void OnRender(DrawingContext dc) { base.OnRender(dc); CPFPen cpfpen = new CPFPen(this.BorderColor, 1f); Stroke stroke = cpfpen.Stroke; Brush brush = cpfpen.Brush; float num = 0f; float num2 = 0f; Point point = new Point(ref num, ref num2); float width = base.ActualSize.Width; float num3 = 0f; Point point2 = new Point(ref width, ref num3); dc.DrawLine(stroke, brush, point, point2); } public float TranslateScrollPoint(int p) { Matrix value = this.canvas.RenderTransform.Value; float num = (float)p; float num2 = 0f; return value.Transform(new Point(ref num, ref num2)).X; } public Rect GetItemBounds(int index) { bool flag = index < 0 || index > this.canvas.Children.Count - 1; if (flag) { throw new ArgumentOutOfRangeException("index"); } UIElement uielement = this.canvas.Children[index]; Visual visual = uielement; float num = 0f; float num2 = 0f; Point point = visual.PointToScreen(new Point(ref num, ref num2)) / this.Root.RenderScaling; Size actualSize = base.ActualSize; return new Rect(ref point, ref actualSize); } public void MoveItem(int index, int targetIndex) { bool flag = index < 0 || index > this.canvas.Children.Count - 1; if (flag) { throw new ArgumentOutOfRangeException("index"); } UIElement visual = this.canvas.Children[index]; this.canvas.Children.RemoveAt(index); bool flag2 = targetIndex > index; if (flag2) { targetIndex--; } this.canvas.Children.Insert(targetIndex, visual); } public void ScrollToItem(int index) { } public float ControlWidth { get; set; } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler SelectedIndexChanged; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler SplitterMoving; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler SheetListClick; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler NewSheetClick; //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler TabMouseDown; internal Grid canvas = new Grid { MarginLeft = 0, MarginTop = 0, Height = "auto", MarginBottom = 1, Name = "tabGrid" }; private Picture newSheetImage; private bool splitterMoving = false; private bool scrollLeftDown = false; private bool scrollRightDown = false; private DispatcherTimer scrollTimer; } }