コード例 #1
0
ファイル: TabsPresenter.cs プロジェクト: Daoting/dt
        protected override Size ArrangeOverride(Size arrangeSize)
        {
            IsLastSheetVisible = false;
            if ((StartIndex < 0) || (StartIndex >= Children.Count))
            {
                StartIndex = 0;
            }

            if (Children.Count > 0)
            {
                for (int i = 0; (i < (StartIndex - 1)) && (i < Children.Count); i++)
                {
                    (Children[i] as SheetTab).Arrange(_rcEmpty);
                }

                double x = 0.0;
                x += Offset;
                double height = arrangeSize.Height;
                double width;
                int    num5 = StartIndex - 1;
                if (num5 >= 0)
                {
                    SheetTab tab = Children[num5] as SheetTab;
                    if (tab.Visible)
                    {
                        width = tab.DesiredSize.Width;
                        tab.Arrange(new Rect(-width, 0.0, width, height));
                        x = 8.0 + Offset;
                    }
                    else
                    {
                        tab.Arrange(_rcEmpty);
                    }
                }

                for (int j = StartIndex; j < Children.Count; j++)
                {
                    SheetTab tab = Children[j] as SheetTab;
                    if (tab.Visible)
                    {
                        width = tab.DesiredSize.Width;
                        tab.Arrange(new Rect(x, 0.0, width, height));
                        x += width;
                    }
                    else
                    {
                        tab.Arrange(_rcEmpty);
                    }
                }
                IsLastSheetVisible = (x + 4.0) < RenderSize.Width;
            }

            _arrangeSize = arrangeSize;
            RectangleGeometry geometry = new RectangleGeometry();

            geometry.Rect = new Rect(0.0, 0.0, arrangeSize.Width, arrangeSize.Height);
            Clip          = geometry;
            return(arrangeSize);
        }
コード例 #2
0
        public void NewTab(int sheetIndex)
        {
            StopTabEditing(false);
            SheetTab tab = new SheetTab(this)
            {
                SheetIndex = sheetIndex
            };
            int count = TabsPresenter.Children.Count;

            if (Excel.TabStripInsertTab && (TabsPresenter.Children.Count > 0))
            {
                count = TabsPresenter.Children.Count - 1;
            }
            TabsPresenter.Children.Insert(count, tab);
            TabsPresenter.ReCalculateStartIndex(0, TabsPresenter.Children.Count - 1);
        }
コード例 #3
0
        void LoadTabs()
        {
            for (int i = 0; i < Excel.Sheets.Count; i++)
            {
                SheetTab tab = new SheetTab(this);
                tab.SheetIndex = i;
                TabsPresenter.Children.Add(tab);
            }

            if (Excel.TabStripInsertTab)
            {
                _newTab = new SheetTab(this);
                TabsPresenter.Children.Add(_newTab);
            }
            ActiveSheet(Excel.ActiveSheetIndex, false);
        }
コード例 #4
0
        void StartTabEditing(Point point)
        {
            SheetTab tab = GetHitSheetTab(point);

            if (tab != null && tab.SheetIndex == Workbook.ActiveSheetIndex && tab != _editingTab)
            {
                if (IsEditing)
                {
                    StopTabEditing(false);
                }

                tab.PrepareForEditing();
                IsEditing   = true;
                _editingTab = tab;
            }
        }
コード例 #5
0
        public void StopTabEditing(bool cancel)
        {
            if (!IsEditing)
            {
                return;
            }

            string text = _editingTab.GetEditText();

            if (!cancel && !string.IsNullOrEmpty(text) && IsValidSheetName(text))
            {
                SheetRenameUndoAction command = new SheetRenameUndoAction(Workbook.Sheets[_editingTab.SheetIndex], text);
                Excel.DoCommand(command);
            }
            _editingTab.PrepareForDisplay();
            _editingTab = null;
            IsEditing   = false;
        }
コード例 #6
0
        void ActiveSheet(int p_sheetIndex, bool raiseEvent)
        {
            if (TabsPresenter.Children.Count == 0 ||
                p_sheetIndex < 0 ||
                p_sheetIndex >= TabsPresenter.Children.Count)
            {
                return;
            }

            SheetTab tab = TabsPresenter.Children[p_sheetIndex] as SheetTab;

            if (tab.SheetIndex == p_sheetIndex && tab != _activeTab)
            {
                if (raiseEvent)
                {
                    CancelEventArgs args = new CancelEventArgs();
                    if (!tab.IsActive)
                    {
                        OnActiveTabChanging((EventArgs)args);
                    }
                    if (!args.Cancel)
                    {
                        if (_activeTab != null)
                        {
                            _activeTab.IsActive = false;
                        }
                        tab.IsActive = true;
                        _activeTab   = tab;
                        OnActiveTabChanged(EventArgs.Empty);
                    }
                }
                else
                {
                    if (_activeTab != null)
                    {
                        _activeTab.IsActive = false;
                    }
                    tab.IsActive = true;
                    _activeTab   = tab;
                }
            }
        }
コード例 #7
0
        public void ProcessTap(Point point)
        {
            SheetTab touchHitSheetTab = GetHitSheetTab(point);

            if (touchHitSheetTab == null)
            {
                return;
            }

            TabsPresenter tabsPresenter = TabsPresenter;

            if (touchHitSheetTab == _newTab)
            {
                if (!Workbook.Protect)
                {
                    OnNewTabNeeded(EventArgs.Empty);
                    if (tabsPresenter.Children.Count > 1)
                    {
                        ActiveSheet(((SheetTab)tabsPresenter.Children[tabsPresenter.Children.Count - 2]).SheetIndex, true);
                    }
                }
            }
            else
            {
                int index = TabsPresenter.Children.IndexOf(touchHitSheetTab);
                if (index == (TabsPresenter.StartIndex - 1))
                {
                    TabsPresenter.NavigateToPrevious();
                }
                else if (TabsPresenter.ReCalculateStartIndex(TabsPresenter.StartIndex, index))
                {
                    TabsPresenter.InvalidateMeasure();
                    TabsPresenter.InvalidateArrange();
                }
                if (touchHitSheetTab != _activeTab)
                {
                    ActiveSheet(touchHitSheetTab.SheetIndex, true);
                }
            }
            Excel.RaiseSheetTabClick(touchHitSheetTab.SheetIndex);
        }
コード例 #8
0
        /// <summary>
        /// Tab项个数不同时重新加载,相同时刷新名称
        /// </summary>
        public void UpdateTabs()
        {
            int cnt = Excel.Sheets.Count;

            if (_newTab != null)
            {
                cnt += 1;
            }
            if (cnt != TabsPresenter.Children.Count)
            {
                TabsPresenter.Children.Clear();
                _newTab = null;
                LoadTabs();
            }
            else if (TabsPresenter.Children.Count > 0)
            {
                foreach (SheetTab tab in TabsPresenter.Children)
                {
                    tab.PrepareForDisplay();
                }
            }
        }
コード例 #9
0
        void ProcessNavigation(int nextIndex)
        {
            SheetTab tab = TabsPresenter.Children[nextIndex] as SheetTab;

            if (((tab != null) && (tab.SheetIndex != -1)) && (tab != null))
            {
                TabsPresenter tabsPresenter = TabsPresenter;
                if (tab == _newTab)
                {
                    if (!Workbook.Protect)
                    {
                        OnNewTabNeeded(EventArgs.Empty);
                        if (tabsPresenter.Children.Count > 1)
                        {
                            ActiveSheet(((SheetTab)tabsPresenter.Children[tabsPresenter.Children.Count - 2]).SheetIndex, true);
                        }
                    }
                }
                else
                {
                    int index = tabsPresenter.Children.IndexOf(tab);
                    if (index == (tabsPresenter.StartIndex - 1))
                    {
                        tabsPresenter.NavigateToPrevious();
                    }
                    else if (tabsPresenter.ReCalculateStartIndex(tabsPresenter.StartIndex, index))
                    {
                        tabsPresenter.InvalidateMeasure();
                        tabsPresenter.InvalidateArrange();
                    }
                    if (tab != _activeTab)
                    {
                        ActiveSheet(tab.SheetIndex, true);
                    }
                }
                Excel.RaiseSheetTabClick(tab.SheetIndex);
            }
        }
コード例 #10
0
        public void ProcessMouseClickSheetTab(PointerRoutedEventArgs args)
        {
            SheetTab hitSheetTab = GetHitSheetTab(args.GetCurrentPoint(null).Position);

            if (hitSheetTab != null)
            {
                TabsPresenter tabsPresenter = TabsPresenter;
                if (hitSheetTab == _newTab)
                {
                    if (!Workbook.Protect)
                    {
                        OnNewTabNeeded(EventArgs.Empty);
                        if (tabsPresenter.Children.Count > 1)
                        {
                            ActiveSheet(((SheetTab)tabsPresenter.Children[tabsPresenter.Children.Count - 2]).SheetIndex, true);
                        }
                    }
                }
                else
                {
                    int index = TabsPresenter.Children.IndexOf(hitSheetTab);
                    if (index == (TabsPresenter.StartIndex - 1))
                    {
                        TabsPresenter.NavigateToPrevious();
                    }
                    else if (TabsPresenter.ReCalculateStartIndex(TabsPresenter.StartIndex, index))
                    {
                        TabsPresenter.InvalidateMeasure();
                        TabsPresenter.InvalidateArrange();
                    }
                    if (hitSheetTab != _activeTab)
                    {
                        ActiveSheet(hitSheetTab.SheetIndex, true);
                    }
                }
                Excel.RaiseSheetTabClick(hitSheetTab.SheetIndex);
            }
        }
コード例 #11
0
 public void UpdateInsertNewTab()
 {
     if (Excel.TabStripInsertTab)
     {
         if (_newTab == null)
         {
             _newTab = new SheetTab(this);
         }
         if (!TabsPresenter.Children.Contains(_newTab))
         {
             TabsPresenter.Children.Add(_newTab);
         }
         if (IsLoaded)
         {
             TabsPresenter.ReCalculateStartIndex(0, TabsPresenter.Children.Count - 1);
         }
     }
     else if (_newTab != null)
     {
         TabsPresenter.Children.Remove(_newTab);
         _newTab = null;
     }
 }