⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabgroupleaf.cs

📁 Magic Library 1.7,有说明文档
💻 CS
📖 第 1 页 / 共 2 页
字号:
            _tabbedGroups.ActiveLeaf = this;
        }

        protected void OnTabPagesCleared()
        {
            // All pages removed, do we need to compact?
            if (_tabbedGroups.AutoCompact)
                _tabbedGroups.Compact();

            // Mark layout as dirty
            if (_tabbedGroups.AutoCalculateDirty)
                _tabbedGroups.Dirty = true;
        }

        protected void OnTabPagesInserted(int index, object value)
        {
            // If there is no currently active leaf then make it us
            if (_tabbedGroups.ActiveLeaf == null)
                _tabbedGroups.ActiveLeaf = this;

            // Mark layout as dirty
            if (_tabbedGroups.AutoCalculateDirty)
                _tabbedGroups.Dirty = true;
        }

        protected void OnTabPagesRemoved(int index, object value)
        {
            if (_tabControl.TabPages.Count == 0)
            {
                // All pages removed, do we need to compact?
                if (_tabbedGroups.AutoCompact)
                    _tabbedGroups.Compact();
            }

            // Mark layout as dirty
            if (_tabbedGroups.AutoCalculateDirty)
                _tabbedGroups.Dirty = true;
        }
        
        protected void OnPopupMenuDisplay(object sender, CancelEventArgs e)
        {
            // Remove all existing menu items
            _tabControl.ContextPopupMenu.MenuCommands.Clear();
            
            // Add our standard set of menus
            _tabControl.ContextPopupMenu.MenuCommands.AddRange(new MenuCommand[]{_mcClose, _mcSep1, 
                                                                                 _mcProm, _mcReba, 
                                                                                 _mcSep2, _mcHorz, 
                                                                                 _mcVert, _mcNext, 
                                                                                 _mcPrev});
        
            // Are any pages selected
            bool valid = (_tabControl.SelectedIndex != -1);
        
            // Define the latest text string
            _mcClose.Text = _tabbedGroups.CloseMenuText;
            _mcProm.Text = _tabbedGroups.ProminentMenuText;
            _mcReba.Text = _tabbedGroups.RebalanceMenuText;
            _mcPrev.Text = _tabbedGroups.MovePreviousMenuText;
            _mcNext.Text = _tabbedGroups.MoveNextMenuText;
            _mcVert.Text = _tabbedGroups.NewVerticalMenuText;
            _mcHorz.Text = _tabbedGroups.NewHorizontalMenuText;
            
            // Only need to close option if the tab has close defined
            _mcClose.Visible = _tabControl.ShowClose && valid;
            _mcSep1.Visible = _tabControl.ShowClose && valid;
            
            // Update the radio button for prominent
            _mcProm.Checked = (_tabbedGroups.ProminentLeaf == this);
            
            // Can only create new group if at least two pages exist
            bool split = valid && (_tabControl.TabPages.Count > 1);

            bool vertSplit = split;
            bool horzSplit = split;
            
            TabGroupSequence tgs = _parent as TabGroupSequence;

            // If we are not the only leaf, then can only split in 
            // the same direction as the group we are in
            if (tgs.Count > 1)
            {
                if (tgs.Direction == Direction.Vertical)
                   vertSplit = false;
                else
                   horzSplit = false;
            }
            
            _mcVert.Visible = vertSplit;
            _mcHorz.Visible = horzSplit;

            // Can only how movement if group exists in that direction
            _mcNext.Visible = valid && (_tabbedGroups.NextLeaf(this) != null);
            _mcPrev.Visible = valid && (_tabbedGroups.PreviousLeaf(this) != null);

            TGContextMenuEventArgs tge = new TGContextMenuEventArgs(this, 
                                                                    _tabControl, 
                                                                    _tabControl.SelectedTab,
                                                                    _tabControl.ContextPopupMenu);
        
            // Generate event so handlers can add/remove/cancel menu
            _tabbedGroups.OnPageContextMenu(tge);
            
            // Pass back cancel value
            e.Cancel = tge.Cancel;
        }
        
        internal void OnClose(object sender, EventArgs e)
        {
            TGCloseRequestEventArgs tge = new TGCloseRequestEventArgs(this, _tabControl, _tabControl.SelectedTab);
        
            // Generate event so handlers can perform appropriate action
            _tabbedGroups.OnPageCloseRequested(tge);
            
            // Still want to close the page?
            if (!tge.Cancel)
                _tabControl.TabPages.Remove(_tabControl.SelectedTab);
        }
        
        internal void OnToggleProminent(object sender, EventArgs e)
        {
            // Toggel the prominent mode
            if (_tabbedGroups.ProminentLeaf == this)
                _tabbedGroups.ProminentLeaf = null;
            else
                _tabbedGroups.ProminentLeaf = this;
        }

        internal void OnRebalance(object sender, EventArgs e)
        {
            _tabbedGroups.Rebalance();
        }
            
        internal void OnMovePrevious(object sender, EventArgs e)
        {
            // Find the previous leaf node
            TabGroupLeaf prev = _tabbedGroups.PreviousLeaf(this);
            
            // Must always be valid!
            if (prev != null)           
                MovePageToLeaf(prev);
        }

        internal void OnMoveNext(object sender, EventArgs e)
        {
            // Find the previous leaf node
            TabGroupLeaf next = _tabbedGroups.NextLeaf(this);
            
            // Must always be valid!
            if (next != null)           
                MovePageToLeaf(next);
        }

        internal void OnNewVertical(object sender, EventArgs e)
        {
            NewVerticalGroup(this, false);
        }

        protected void OnNewHorizontal(object sender, EventArgs e)
        {
            NewHorizontalGroup(this, false);    
        }

        internal void NewVerticalGroup(TabGroupLeaf sourceLeaf, bool before)
        {
            TabGroupSequence tgs = this.Parent as TabGroupSequence;
        
            // We must have a parent sequence!
            if (tgs != null)
            {
                tgs.Direction = Direction.Vertical;
                AddGroupToSequence(tgs, sourceLeaf, before);
            }
        }
        
        internal void NewHorizontalGroup(TabGroupLeaf sourceLeaf, bool before)
        {
            TabGroupSequence tgs = this.Parent as TabGroupSequence;
        
            // We must have a parent sequence!
            if (tgs != null)
            {
                tgs.Direction = Direction.Horizontal;
                AddGroupToSequence(tgs, sourceLeaf, before);
            }
        }
        
        internal void MovePageToLeaf(TabGroupLeaf leaf)
        {
            // Remember original auto compact mode
            bool autoCompact = _tabbedGroups.AutoCompact;

            // Turn mode off as it interferes with reorganisation
            _tabbedGroups.AutoCompact = false;

            // Get the requested tab page to be moved to new leaf
            TabPage tp = _tabControl.SelectedTab;

            // Remove page from ourself
            _tabControl.TabPages.Remove(tp);
            
            // Add into the new leaf
            leaf.TabPages.Add(tp);

            // Make new leaf the active one
            _tabbedGroups.ActiveLeaf = leaf;
                
            TabControl tc = leaf.GroupControl as Controls.TabControl;
                
            // Select the newly added page
            tc.SelectedTab = tp;

            // Reset compacting mode as we have updated the structure
            _tabbedGroups.AutoCompact = autoCompact;
            
            // Do we need to compact?
            if (_tabbedGroups.AutoCompact)
                _tabbedGroups.Compact();
        }

        protected void AddGroupToSequence(TabGroupSequence tgs, TabGroupLeaf sourceLeaf, bool before)
        {
            // Remember original auto compact mode
            bool autoCompact = _tabbedGroups.AutoCompact;

            // Turn mode off as it interferes with reorganisation
            _tabbedGroups.AutoCompact = false;

            // Find our index into parent collection
            int pos = tgs.IndexOf(this);
                
            TabGroupLeaf newGroup = null;

            // New group inserted before existing one?                
            if (before)
                newGroup = tgs.InsertNewLeaf(pos);
            else
            {
                // No, are we at the end of the collection?
                if (pos == (tgs.Count - 1))
                    newGroup = tgs.AddNewLeaf();
                else
                    newGroup = tgs.InsertNewLeaf(pos + 1);
            }
                     
            // Get tab control for source leaf
            Controls.TabControl tc = sourceLeaf.GroupControl as Controls.TabControl;
                        
            TabPage tp = tc.SelectedTab;

            // Remove page from ourself
            tc.TabPages.Remove(tp);
                    
            // Add into the new leaf
            newGroup.TabPages.Add(tp);

            // Reset compacting mode as we have updated the structure
            _tabbedGroups.AutoCompact = autoCompact;

            // Do we need to compact?
            if (_tabbedGroups.AutoCompact)
                _tabbedGroups.Compact();
        }
        
        protected void OnPageDragStart(object sender, MouseEventArgs e)
        {
            // Save the current cursor value
            _savedCursor = _tabControl.Cursor;
            
            // Manager will create hot zones and draw dragging rectangle
            _targetManager = new TargetManager(_tabbedGroups, this, _tabControl);
        }
 
        protected void OnPageDragMove(object sender, MouseEventArgs e)
        {
            // Convert from Control coordinates to screen coordinates
            Point mousePos = _tabControl.PointToScreen(new Point(e.X, e.Y));

            // Let manager decide on drawing rectangles and setting cursor
            _targetManager.MouseMove(mousePos);
        }

        protected void OnPageDragEnd(object sender, MouseEventArgs e)
        {
            // Give manager chance to action request and cleanup
            _targetManager.Exit();

            // No longer need the manager
            _targetManager = null;
            
            // Restore the original cursor
            _tabControl.Cursor = _savedCursor;
        }

        protected void OnPageDragQuit(object sender, MouseEventArgs e)
        {
            // Give manager chance to cleanup
            _targetManager.Quit();
        
            // No longer need the manager
            _targetManager = null;

            // Restore the original cursor
            _tabControl.Cursor = _savedCursor;
        }

        
        protected void OnControlDragEnter(object sender, DragEventArgs drgevent)
        {
            _dragEntered = ValidFormat(drgevent);
        
            // Do we allow the drag to occur?
            if (_dragEntered)
            {
                // Must draw a drag indicator
                DrawDragIndicator();
                
                // Update the allowed effects
                drgevent.Effect = DragDropEffects.Copy;
            }
        }

        protected void OnControlDragDrop(object sender, DragEventArgs drgevent)
        {
            // Do we allow the drop to occur?
            if (_dragEntered)
            {
                // Must remove the drag indicator
                DrawDragIndicator();
                
                // Generate an event so caller can perform required action
                _tabbedGroups.OnExternalDrop(this, _tabControl, GetDragProvider(drgevent));
            }

            _dragEntered = false;
        }

        protected void OnControlDragLeave(object sender, EventArgs e)
        {
            // Do we need to remove the drag indicator?
            if (_dragEntered)
                DrawDragIndicator();
                
            _dragEntered = false;
        }
        
        protected bool ValidFormat(DragEventArgs e)
        {
            return e.Data.GetDataPresent(typeof(TabbedGroups.DragProvider));
        }
        
        protected TabbedGroups.DragProvider GetDragProvider(DragEventArgs e)
        {
            return (TabbedGroups.DragProvider)e.Data.GetData(typeof(TabbedGroups.DragProvider));
        }
        
        protected void DrawDragIndicator()
        {
            // Create client rectangle
            Rectangle clientRect = new Rectangle(new Point(0,0), _tabControl.ClientSize);
            
            // Draw drag indicator around whole control
            TargetManager.DrawDragRectangle(_tabControl.RectangleToScreen(clientRect));
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -