コード例 #1
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (mouseDownTab != null)
            {
                ActiveTab = mouseDownTab;
                mouseDownTab.SideTabStatus = SideTabStatus.Normal;
                mouseDownTab = null;
            }

            ExitRenameMode();
            Refresh();
            base.OnMouseUp(e);
        }
コード例 #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            int      i = 0;

            int lastUpperY = 0;

            for (; i < sideTabs.Count; ++i)
            {
                SideTab tab = sideTabs[i];

                int yPos = i * (Font.Height + 4 + 1);
                tab.DrawTabHeader(g, Font, new Point(0, yPos), Width);
                lastUpperY = yPos + Font.Height + 4;

                if (tab == activeTab)
                {
                    break;
                }
            }

            int bottom = Height;

            for (int j = sideTabs.Count - 1; j > i; --j)
            {
                SideTab tab = sideTabs[j];

                int yPos = Height - (-j + sideTabs.Count) * (Font.Height + 4 + 1);

                if (yPos < lastUpperY + (Font.Height + 4 + 1))
                {
                    break;
                }

                bottom = yPos;
                tab.DrawTabHeader(g, Font, new Point(0, yPos), Width);
            }

            if (activeTab != null)
            {
                bool b = scrollBar.Maximum > (bottom - lastUpperY) / 20 || scrollBar.Value != 0;
                scrollBar.Visible   = b;
                activeTabMemberArea = new Rectangle(0, lastUpperY,
                                                    Width - (scrollBar.Visible ? (SystemInformation.VerticalScrollBarWidth) : 0) - 4, bottom - lastUpperY);
                sideTabContent.Bounds = activeTabMemberArea;
                scrollBar.Location    = new Point(Width - SystemInformation.VerticalScrollBarWidth - 4,
                                                  lastUpperY);
                scrollBar.Width  = SystemInformation.VerticalScrollBarWidth;
                scrollBar.Height = activeTabMemberArea.Height;
            }
        }
コード例 #3
0
 protected void ExitRenameMode()
 {
     if (renameTab != null)
     {
         renameTextBox.Visible = false;
         renameTab             = null;
         doAddTab = false;
     }
     else if (renameTabItem != null)
     {
         renameTextBox.Visible = false;
         renameTabItem         = null;
     }
 }
コード例 #4
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button == MouseButtons.Left)
            {
                mouseDownPosition = e.Location;

                SideTab tab = GetTabAt(e.X, e.Y);
                if (tab != null)
                {
                    mouseDownTab      = tab;
                    tab.SideTabStatus = SideTabStatus.Selected;
                    Refresh();
                }
            }
        }
コード例 #5
0
        public void StartRenamingOf(SideTab tab)
        {
            int index = Tabs.IndexOf(tab);

            renameTab = Tabs[index];
            Point location = GetLocation(renameTab);

            location.X            += 3;
            location.Y            += 1;
            renameTextBox.Location = location;
            renameTextBox.Width    = Width - 10;
            renameTextBox.Height   = Font.Height - 2;
            renameTextBox.Text     = renameTab.Name;
            renameTextBox.Visible  = true;
            renameTextBox.Focus();
        }
コード例 #6
0
        public Point GetLocation(SideTab whichTab)
        {
            int i = 0;

            int lastUpperY = 0;

            for (; i < sideTabs.Count; ++i)
            {
                SideTab tab = sideTabs[i];

                int yPos = i * (Font.Height + 4 + 1);
                if (tab == whichTab)
                {
                    return(new Point(0, yPos));
                }
                lastUpperY = yPos + Font.Height + 4;
                if (tab == activeTab)
                {
                    break;
                }
            }

            int bottom = Height;

            for (int j = sideTabs.Count - 1; j > i; --j)
            {
                SideTab tab = sideTabs[j];

                int yPos = Height - (-j + sideTabs.Count) * (Font.Height + 4 + 1);

                if (yPos < lastUpperY + (Font.Height + 4 + 1))
                {
                    break;
                }

                bottom = yPos;
                if (tab == whichTab)
                {
                    return(new Point(0, yPos));
                }
            }

            return(new Point(-1, -1));
        }
コード例 #7
0
        public int GetTabIndexAt(int x, int y)
        {
            int lastUpperY = 0;
            int i          = 0;

            for (; i < sideTabs.Count; ++i)
            {
                SideTab tab = sideTabs[i];

                int yPos = i * (Font.Height + 4 + 1);

                lastUpperY = yPos + Font.Height + 4;

                if (y >= yPos && y <= lastUpperY)
                {
                    return(i);
                }
                if (tab == activeTab)
                {
                    break;
                }
            }

            for (int j = sideTabs.Count - 1; j > i; --j)
            {
                SideTab tab = sideTabs[j];

                int yPos = Height - (-j + sideTabs.Count) * (Font.Height + 4 + 1);

                if (yPos < lastUpperY + (Font.Height + 4 + 1))
                {
                    break;
                }
                if (y >= yPos && y <= yPos + Font.Height + 4)
                {
                    return(j);
                }
            }
            return(-1);
        }
コード例 #8
0
ファイル: SideTab.cs プロジェクト: carlhuth/GenXSource
 public SideTabEventArgs(SideTab tab)
 {
     this.tab = tab;
 }
コード例 #9
0
        protected override void OnDragOver(DragEventArgs e)
        {
            ExitRenameMode();
            base.OnDragOver(e);

            Point p = PointToClient(new Point(e.X, e.Y));

            if (e.Data.GetDataPresent(typeof(SideTabItem)))
            {
                ClearDraggings(activeTab);
                SideTab tab = GetTabAt(p.X, p.Y);
                if (tab != null && tab != Tabs.DragOverTab)
                {
                    if (tab.CanDragDrop)
                    {
                        Tabs.DragOverTab = tab;
                    }
                    else
                    {
                        Tabs.DragOverTab = null;
                    }
                    Refresh();
                }
                if (Tabs.DragOverTab != null && Tabs.DragOverTab.CanDragDrop)
                {
                    e.Effect = GetDragDropEffect(e);
                }
                else
                {
                    e.Effect = DragDropEffects.None;
                }
            }
            else if (e.Data.GetDataPresent(typeof(string)))
            {
                SideTab oldTab = Tabs.DragOverTab;
                if (activeTabMemberArea.Contains(p.X, p.Y))
                {
                    Tabs.DragOverTab = activeTab;
                }
                else
                {
                    Tabs.DragOverTab = GetTabAt(p.X, p.Y);
                }
                if (oldTab != Tabs.DragOverTab)
                {
                    Refresh();
                }
            }
            else if (e.Data.GetDataPresent(typeof(SideTab)))
            {
                int tabIndex = GetTabIndexAt(p.X, p.Y);
                if (tabIndex != -1)
                {
                    SideTab tab = Tabs.DragOverTab;
                    Tabs.Remove(tab);
                    Tabs.Insert(tabIndex, tab);
                    Refresh();
                }
                e.Effect = DragDropEffects.Move;
            }
        }
コード例 #10
0
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            int index;

            if (base.ProcessCmdKey(ref msg, keyData))
            {
                return(true);
            }
            bool isInRenameMode = renameTab != null || renameTabItem != null;

            switch (keyData)
            {
            case Keys.Home:
                if (activeTab.Items.Count > 0 && !isInRenameMode)
                {
                    activeTab.ChoosedItem = activeTab.Items[0];
                    EnsureVisible(activeTab.ChoosedItem);
                    Refresh();
                }
                break;

            case Keys.End:
                if (activeTab.Items.Count > 0 && !isInRenameMode)
                {
                    activeTab.ChoosedItem = activeTab.Items[activeTab.Items.Count - 1];
                    EnsureVisible(activeTab.ChoosedItem);
                    Refresh();
                }
                break;

            case Keys.PageUp:
                if (activeTab.Items.Count > 0 && !isInRenameMode)
                {
                    index = Math.Max(0, activeTab.Items.IndexOf(activeTab.ChoosedItem) - scrollBar.LargeChange);
                    activeTab.ChoosedItem = activeTab.Items[index];
                    EnsureVisible(activeTab.ChoosedItem);
                    Refresh();
                }
                break;

            case Keys.PageDown:
                if (activeTab.Items.Count > 0 && !isInRenameMode)
                {
                    index = Math.Min(activeTab.Items.Count - 1, activeTab.Items.IndexOf(activeTab.ChoosedItem) + scrollBar.LargeChange);
                    activeTab.ChoosedItem = activeTab.Items[index];
                    EnsureVisible(activeTab.ChoosedItem);
                    Refresh();
                }
                break;

            case Keys.Down:
                if (activeTab.Items.Count > 0 && !isInRenameMode)
                {
                    if (activeTab.ChoosedItem != null)
                    {
                        activeTab.ChoosedItem = activeTab.Items[Math.Min(activeTab.Items.Count - 1, activeTab.Items.IndexOf(activeTab.ChoosedItem) + 1)];
                    }
                    else
                    {
                        activeTab.ChoosedItem = activeTab.Items[0];
                    }
                    activeTab.SelectedItem = null;
                    EnsureVisible(activeTab.ChoosedItem);
                    Refresh();
                }
                return(true);

            case Keys.Up:
                if (activeTab.Items.Count > 0 && !isInRenameMode)
                {
                    if (activeTab.ChoosedItem != null)
                    {
                        activeTab.ChoosedItem = activeTab.Items[Math.Max(0, activeTab.Items.IndexOf(activeTab.ChoosedItem) - 1)];
                    }
                    else
                    {
                        activeTab.ChoosedItem = activeTab.Items[0];
                    }
                    activeTab.SelectedItem = null;
                    EnsureVisible(activeTab.ChoosedItem);
                    Refresh();
                }
                return(true);

            case Keys.Control | Keys.Up:
                ActiveTab = Tabs[Math.Max(0, Tabs.IndexOf(ActiveTab) - 1)];
                Refresh();
                return(true);

            case Keys.Control | Keys.Down:
                ActiveTab = Tabs[Math.Min(Tabs.Count - 1, Tabs.IndexOf(ActiveTab) + 1)];
                Refresh();
                return(true);

            case Keys.Return:
                if (renameTab != null)
                {
                    renameTab.Name = renameTextBox.Text;
                    ExitRenameMode();
                }
                else if (renameTabItem != null)
                {
                    renameTabItem.Name = renameTextBox.Text;
                    ExitRenameMode();
                }
                return(true);

            case Keys.Escape:
                if (renameTab != null)
                {
                    if (doAddTab)
                    {
                        Tabs.RemoveAt(Tabs.Count - 1);
                        renameTab             = null;
                        renameTextBox.Visible = false;
                        doAddTab = false;
                        Refresh();
                    }
                    else
                    {
                        ExitRenameMode();
                    }
                }
                else if (renameTabItem != null)
                {
                    ExitRenameMode();
                }
                return(true);
            }
            return(false);
        }