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

📄 tabbedgroups.cs

📁 Magic Library 1.7,有说明文档
💻 CS
📖 第 1 页 / 共 4 页
字号:
                    ActiveLeaf = tgs[i] as TabGroupLeaf;
                    return;  
                }
                else
                {
                    // Need to make a recursive check inside group
                    if (RecursiveActiveInSequence(tgs[i] as TabGroupSequence, true))
                        return;
                }
            }
            
            // Now try each entry before that given
            for(int i=index-1; i>=0; i--)
            {
                // Is this the needed leaf node?
                if (tgs[i].IsLeaf)
                {
                    // Make it active, and finish
                    ActiveLeaf = tgs[i] as TabGroupLeaf;
                    return;  
                }
                else
                {
                    // Need to make a recursive check inside group
                    if (RecursiveActiveInSequence(tgs[i] as TabGroupSequence, false))
                        return;
                }
            }
            
            // Still no luck, try our own parent
            if (tgs.Parent != null)
                MoveActiveInSequence(tgs.Parent as TabGroupSequence, tgs);
        }
        
        protected bool RecursiveActiveInSequence(TabGroupSequence tgs, bool forwards)
        {
            int count = tgs.Count;
        
            for(int i=0; i<count; i++)
            {
                // Index depends on which direction we are processing
                int index = (forwards == true) ? i : (tgs.Count - i - 1);
                
                // Is this the needed leaf node?
                if (tgs[index].IsLeaf)
                {
                    // Make it active, and finish
                    ActiveLeaf = tgs[index] as TabGroupLeaf;
                    return true;
                }
                else
                {
                    // Need to make a recursive check inside group
                    if (RecursiveActiveInSequence(tgs[index] as TabGroupSequence, forwards))
                        return true;
                }
            }
            
            // Still no luck
            return false;
        }
        
        protected void Notify(TabGroupBase.NotifyCode notifyCode)
        {
            // Propogate change notification only is we have a root sequence
            if (_root != null)
                _root.Notify(notifyCode);
        }
        
        internal void EnforceAtLeastOneLeaf()
        {
            // Should not add items during compacting operation
            if (!_compacting)
            {
                // Ensure we enfore policy of at least one leaf
                if (_atLeastOneLeaf)
                {
                    // Is there at least one?
                    if (_numLeafs == 0)
                    {
                        // No, create a default entry for the root sequence
                        _root.AddNewLeaf();
                        
                        // Update the active leaf
                        _activeLeaf = FirstLeaf();

                        // Mark layout as dirty
                        if (_autoCalculateDirty)
                            _dirty = true;
                    }
                }
            }
        }
        
        internal void GroupRemoved(TabGroupBase tgb)
        {
            // Decrease count of leafs entries for each leaf that exists
            // which in the hierarchy that is being removed
            
            if (tgb.IsLeaf)
                _numLeafs--;
            else
            {
                TabGroupSequence tgs = tgb as TabGroupSequence;
            
                // Recurse into processing each child item
                for(int i=0; i<tgs.Count; i++)
                    GroupRemoved(tgs[i]);
            }
            
            // Mark layout as dirty
            if (_autoCalculateDirty)
                _dirty = true;
        }
         
        public bool PreFilterMessage(ref Message msg)
        {
            Form parentForm = this.FindForm();

            // Only interested if the Form we are on is activate (i.e. contains focus)
            if ((parentForm != null) && (parentForm == Form.ActiveForm) && parentForm.ContainsFocus)
            {		
                switch(msg.Msg)
                {
                    case (int)Win32.Msgs.WM_KEYDOWN:
                        // Ignore keyboard input if the control is disabled
                        if (this.Enabled)
                        {
                            // Find up/down state of shift and control keys
                            ushort shiftKey = User32.GetKeyState((int)Win32.VirtualKeys.VK_SHIFT);
                            ushort controlKey = User32.GetKeyState((int)Win32.VirtualKeys.VK_CONTROL);

                            // Basic code we are looking for is the key pressed
                            int code = (int)msg.WParam;

                            // Is SHIFT pressed?
                            bool shiftPressed = (((int)shiftKey & 0x00008000) != 0);

                            // Is CONTROL pressed?
                            bool controlPressed = (((int)controlKey & 0x00008000) != 0);

                            // Was the TAB key pressed?
                            if ((code == (int)Win32.VirtualKeys.VK_TAB) && controlPressed)
                            {
                                if (shiftPressed)
                                    return SelectPreviousTab();
                                else
                                    return SelectNextTab();
                            }
                            else
                            {
                                // Plus the modifier for SHIFT...
                                if (shiftPressed)
                                    code += 0x00010000;

                                // Plus the modifier for CONTROL
                                if (controlPressed)
                                    code += 0x00020000;

                                // Construct shortcut from keystate and keychar
                                Shortcut sc = (Shortcut)(code);

                                // Search for a matching command
                                return TestShortcut(sc);
                            }
                        }
                        break;
                    case (int)Win32.Msgs.WM_SYSKEYDOWN:
                        // Ignore keyboard input if the control is disabled
                        if (this.Enabled)
                        {
                            if ((int)msg.WParam != (int)Win32.VirtualKeys.VK_MENU)
                            {
                                // Construct shortcut from ALT + keychar
                                Shortcut sc = (Shortcut)(0x00040000 + (int)msg.WParam);
		
                                // Search for a matching command
                                return TestShortcut(sc);
                            }
                        }
                        break;
                    default:
                        break;
                }
            }

            return false;
        }
        
        protected bool TestShortcut(Shortcut sc)
        {
            bool result = false;
        
            // Must have an active leaf for shortcuts to operate against
            if (_activeLeaf != null)
            {
                Controls.TabControl tc = _activeLeaf.GroupControl as Controls.TabControl;
            
                // Must have an active tab for these shortcuts to work against
                if (tc.SelectedTab != null)
                {
                    // Close selected page requested?
                    if (sc.Equals(_closeShortcut))
                    {
                        _activeLeaf.OnClose(_activeLeaf, EventArgs.Empty);
                        result = true;
                    }

                    // Toggle the prominence state?
                    if (sc.Equals(_prominentShortcut))
                    {
                        _activeLeaf.OnToggleProminent(_activeLeaf, EventArgs.Empty);
                        result = true;
                    }
                        
                    // Move page to the next group?
                    if (sc.Equals(_moveNextShortcut))
                    {
                        _activeLeaf.OnMoveNext(_activeLeaf, EventArgs.Empty);
                        result = true;
                    }
                
                    // Move page to the previous group?
                    if (sc.Equals(_movePreviousShortcut))
                    {
                        _activeLeaf.OnMovePrevious(_activeLeaf, EventArgs.Empty);
                        result = true;
                    }
                
                    // Cannot split a group unless at least two entries exist                
                    if (tc.TabPages.Count > 1)
                    {
                        bool allowVert = false;
                        bool allowHorz = false;
                        
                        if (_root.Count <= 1)
                        {
                            allowVert = true;
                            allowHorz = true;
                        }
                        else
                        {
                            if (_root.Direction == Direction.Vertical)
                                allowVert = true;
                            else
                                allowHorz = true;
                        }
                    
                        // Create two vertical groups
                        if (allowHorz && sc.Equals(_splitVerticalShortcut))
                        {
                            _activeLeaf.NewHorizontalGroup(_activeLeaf, false);
                            result = true;
                        }

                        // Create two horizontal groups
                        if (allowVert && sc.Equals(_splitHorizontalShortcut))
                        {
                            _activeLeaf.NewVerticalGroup(_activeLeaf, false);
                            result = true;
                        }
                    }
                }
                
                // Request to rebalance all spacing
                if (sc.Equals(_rebalanceShortcut))
                {
                    _activeLeaf.OnRebalance(_activeLeaf, EventArgs.Empty);
                    result = true;
                }
            }

            return result;
        }
        
        protected bool SelectNextTab()
        {
            // If no active leaf...
            if (_activeLeaf == null)
                SelectFirstPage();
            else
            {
                bool selectFirst = false;
                TabGroupLeaf startLeaf = _activeLeaf;
                TabGroupLeaf thisLeaf = startLeaf;
                
                do
                {
                    // Access to the embedded tab control
                    Controls.TabControl tc = thisLeaf.GroupControl as Controls.TabControl;
                
                    // Does it have any pages?
                    if (tc.TabPages.Count > 0)
                    {
                        // Are we allowed to select the first page?
                        if (selectFirst)
                        {
                            // Do it and exit loop
                            tc.SelectedIndex = 0;
                            
                            // Must ensure this becomes the active leaf
                            if (thisLeaf != _activeLeaf)
                                ActiveLeaf = thisLeaf;
                                
                            break;
                        }
                        else
                        {
                            // Is there another page after the selected one?
                            if (tc.SelectedIndex < tc.TabPages.Count - 1)
                            {
                                // Select new page and exit loop
                                tc.SelectedIndex = tc.SelectedIndex + 1;
                                break;
                            }         
                        }           
                    }
                    
                    selectFirst = true;
                    
                    // Find the next leaf in sequence
                    thisLeaf = NextLeaf(thisLeaf);
                    
                    // No more leafs, wrap back to first
                    if (thisLeaf == null)
                        thisLeaf = FirstLeaf();

                    // Back at starting leaf?
                    if (thisLeaf == startLeaf)
                    {
                        // If it was not the first page that we started from
                        if (tc.SelectedIndex > 0)
                        {
                            // Then we have circles all the way around, select first page
                            tc.SelectedIndex = 0;
                        }
                    }

                } while(thisLeaf != startLeaf);
            }
            
            return true;
        }

        protected bool SelectPreviousTab()
        {
            // If no active leaf...
            if (_activeLeaf == null)
                SelectLastPage();
            else
            {
                bool selectLast = false;
                TabGroupLeaf startLeaf = _activeLeaf;
                TabGroupLeaf thisLeaf = startLeaf;
                
                do
                {
                    // Access to the embedded tab control
                    Controls.TabControl tc = thisLeaf.GroupControl as Controls.TabControl;
                
                    // Does it have any pages?
                    if (tc.TabPages.Count > 0)
                    {
                        // Are we allowed to select the last page?
                        if (selectLast)
                        {
                            // Do it and exit loop
                            tc.SelectedIndex = tc.TabPages.Count - 1;
                            
                            // Must ensure this becomes the active leaf
                            if (thisLeaf != _activeLeaf)
                                ActiveLeaf = thisLeaf;
                                
                            break;
                        }
                        else
                        {
                            // Is there another page before the selected one?
                            if (tc.SelectedIndex > 0)
                            {
                                // Select previous page and exit loop
                                tc.SelectedIndex = tc.SelectedIndex - 1;
                                break;
                            }         
                        }           
                    }
                    
                    selectLast = true;
                    
                    // Find the previous leaf in sequence
                    thisLeaf = PreviousLeaf(thisLeaf);
                    
                    // No more leafs, wrap back to first
                    if (thisLeaf == null)
                        thisLeaf = LastLeaf();

                    // Back at starting leaf?
                    if (thisLeaf == startLeaf)
                    {
                        // If it was not the first page that we started from
                        if (tc.SelectedIndex == 0)
                        {
                            // Then we have circles all the way around, select last page
                            tc.SelectedIndex = tc.TabPages.Count - 1;
                        }
                    }

                } while(thisLeaf != startLeaf);
            }
            
            return true;
        }

        protected void SelectFirstPage()
        {
            // Find the first leaf
            ActiveLeaf = FirstLeaf();
                    
            // Did we find a leaf?
            if (_activeLeaf != null)
            {
                // Is there a page that can be selected?
                if (_activeLeaf.TabPages.Count > 0)
                    _activeLeaf.TabPages[0].Selected = true;
            }
        }
        
        protected void SelectLastPage()
        {
            // Find the first leaf
            ActiveLeaf = LastLeaf();
                    
            // Did we find a leaf?
            if (_activeLeaf != null)
            {
                // Is there a page that can be selected?
                if (_activeLeaf.TabPages.Count > 0)
                    _activeLeaf.TabPages[_activeLeaf.TabPages.Count - 1].Selected = true;
            }
        }
    }
}

⌨️ 快捷键说明

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