public DragDropTabVisual(TabItem tab)
            : this()
        {
            Bitmap buffer = new Bitmap(tab.Width, tab.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            tab.DrawToBitmap(buffer, new Rectangle(0, 0, tab.Width, tab.Height));

            pictureBox1.Image = buffer;
        }
 public void Insert(int index, TabItem tab)
 {
     innerList.Insert(index, tab);
     owner.ItemListChanged(tab, false);
 }
Exemple #3
0
        public void ItemListChanged(TabItem[] items, bool remove)
        {
            // remove from control list
            foreach(TabItem tabItem in items) {
                if(remove) {
                    this.Controls.Remove(tabItem);
                }
                else {
                    if(Controls.Contains(tabItem) == false) {
                        this.Controls.Add(tabItem);
                    }
                }
            }

            LayoutTabs();
        }
 public void Remove(TabItem tab)
 {
     innerList.Remove(tab);
 }
 public int IndexOf(TabItem tab)
 {
     return innerList.IndexOf(tab);
 }
        public void Add(string tabText, Image image)
        {
            TabItem tab = new TabItem();

            tab.TabText = tabText;
            tab.Image = image;

            Add(tab);
        }
Exemple #7
0
        public TabItemResizeGlyph(BehaviorService behaviorSvc, Control control, Adorner glyphAdorner,
            ISelectionService selectionService, IComponentChangeService changeService)
            : base(new TabItemResizeBehavior(control as TabItem))
        {
            service = behaviorSvc;
            tab = control as TabItem;
            adorner = glyphAdorner;
            this.selectionService = selectionService;
            this.changeService = changeService;

            // add events
            selectionService.SelectionChanged += OnSelectionChanged;
            changeService.ComponentChanged += OnComponentChanged;
        }
Exemple #8
0
        public override void Initialize(IComponent component)
        {
            base.Initialize(component);

            tabItem = component as TabItem;
            InitializeServices();

            // initialize adorners
            adorner = new Adorner();

            //BehaviorService.Adorners.Clear();
            BehaviorService.Adorners.Add(adorner);
            AutoResizeHandles = true;
            // add glyphs
            selectionGlyph = new TabItemResizeGlyph(BehaviorService, tabItem,
                                                    adorner, selectionService, changeService);
            adorner.Glyphs.Add(selectionGlyph);
        }
Exemple #9
0
        private int GetReorderInsertLocation(TabItem tab, Point mousePosition)
        {
            Point location = MousePositionToHost(tab, mousePosition);

            // constrain the location in the bounds of the host
            location = ConstrainPositionToHost(location);
            TabItem hoveredTab = this.GetChildAtPoint(location) as TabItem;

            if(hoveredTab != null) {
                return tabs.IndexOf(hoveredTab);
            }

            return -1; // no tab found under cursor
        }
Exemple #10
0
        private InsertDirection GetInsertDirection(TabItem tab, Point mousePosition, int insertIndex)
        {
            Point location = MousePositionToHost(tab, mousePosition);
            int tabIndex = tabs.IndexOf(tab);

            // check the type of insertion
            if(insertIndex == tabIndex || insertIndex == -1) {
                // invalid insertion type
                return InsertDirection.None;
            }
            else {
                TabItem targetTab = tabs[insertIndex];

                if((_tabAlignment == TabAlignment.Top) ||
                   (_tabAlignment == TabAlignment.Bottom)) {
                    if((location.X - targetTab.Left) <= targetTab.Width / 2) {
                        // left side of the tab, check if valid
                        if(insertIndex != tabIndex + 1) {
                            return InsertDirection.Left;
                        }
                        else {
                            return InsertDirection.None;
                        }
                    }
                    else {
                        // right side of the tab, check if valid
                        if(insertIndex != tabIndex - 1) {
                            return InsertDirection.Rigth;
                        }
                        else {
                            return InsertDirection.None;
                        }
                    }
                }
                else {
                    if((location.Y - targetTab.Top) <= targetTab.Height / 2) {
                        // left side of the tab, check if valid
                        if(insertIndex != tabIndex + 1) {
                            return InsertDirection.Left;
                        }
                        else {
                            return InsertDirection.None;
                        }
                    }
                    else {
                        // right side of the tab, check if valid
                        if(insertIndex != tabIndex - 1) {
                            return InsertDirection.Rigth;
                        }
                        else {
                            return InsertDirection.None;
                        }
                    }
                }
            }
        }
Exemple #11
0
 private Color GetCurrentTabBackColor(TabItem tab)
 {
     if(tab.Selected) {
         return tab.SelectedBackColor;
     }
     else {
         return tab.BackColor;
     }
 }
Exemple #12
0
        public void TabUpdateDrag(TabItem tab, Point mousePosition)
        {
            if(reorderingVisual != null) {
                // update the position of the visual
                reorderingVisual.Location = GetVisualLocation(tab, mousePosition);
            }

            // get the index of the tab below the mouse
            int insertIndex = GetReorderInsertLocation(tab, mousePosition);
            lastInsertIndex = insertIndex == -1 ? lastInsertIndex : insertIndex;

            // get the insert direction
            lastInsertDirection = GetInsertDirection(tab, mousePosition, lastInsertIndex);
            this.Invalidate(); // force the host to draw the insertion marker
        }
Exemple #13
0
        public void TabStartDrag(TabItem tab, Point mousePosition)
        {
            reorderingVisual = new DragDropTabVisual(tab);

            // set visual location and show it
            reorderingVisual.Location = GetVisualLocation(tab, mousePosition);
            reorderingVisual.Show();

            // refocus the main form
            Form parentForm = this.FindForm();

            if(parentForm != null) {
                parentForm.Activate();
            }

            // set the tab that is reordered
            reorderingTab = tab;
            reordering = true;
        }
Exemple #14
0
        public void TabItemSelected(TabItem item)
        {
            // deselect all other tabs
            for(int i = 0; i < tabs.Count; i++) {
                if(tabs[i] != item) {
                    tabs[i].Selected = false;
                }
            }

            Relayout();
        }
Exemple #15
0
        public void TabEndDrag(TabItem tab, Point mousePosition)
        {
            if(reorderingVisual != null) {
                // destroy the visual
                reorderingVisual.Hide();
                reorderingVisual.Dispose();
                reorderingVisual = null;
            }

            // do the reordering
            // get the index of the tab below the mouse
            int insertIndex = GetReorderInsertLocation(tab, mousePosition);

            // get the insert direction
            lastInsertDirection = GetInsertDirection(tab, mousePosition, insertIndex);

            if(lastInsertDirection != InsertDirection.None) {
                if(lastInsertDirection == InsertDirection.Left) {
                    InsertTabAt(reorderingTab, insertIndex);
                }
                else {
                    InsertTabAt(reorderingTab, insertIndex + 1);
                }
            }

            reorderingTab = null;

            // remove insertion marker
            lastInsertDirection = InsertDirection.None;
            this.Invalidate();
            reordering = false;
        }
 public void Remove(TabItem tab)
 {
     innerList.Remove(tab);
 }
Exemple #17
0
        public TabItemActionList(IComponent component)
            : base(component)
        {
            tabItem = component as TabItem;
            service = GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;

            IDesignerHost host = Component.Site.GetService(typeof(IDesignerHost)) as IDesignerHost;
            tabItemDesigner = host.GetDesigner(component) as TabItemDesigner;
        }
Exemple #18
0
 private int GetTabHeight(TabItem item)
 {
     if(item.Selected) {
         return item.SelectedTabHeigth == 0 ? _selectedTabHeight : item.SelectedTabHeigth;
     }
     else {
         return item.TabHeigth == 0 ? _tabHeight : item.TabHeigth;
     }
 }
Exemple #19
0
 public TabItemResizeBehavior(TabItem tab)
 {
     this.tab = tab;
 }
Exemple #20
0
        private Point GetVisualLocation(TabItem tab, Point mousePosition)
        {
            Point location = Point.Empty;

            switch(_tabAlignment) {
            case TabAlignment.Top: {
                    location = new Point(KeepInHostWidth(tab.Left + mousePosition.X - tab.Width / 2, tab.Width),
                                         this.Height - tab.Height);
                    break;
                }
                case TabAlignment.Bottom: {
                    location = new Point(KeepInHostWidth(tab.Left + mousePosition.X - tab.Width / 2, tab.Width), 0);
                    break;
                }
                case TabAlignment.Left: {
                        location = new Point(0, KeepInHostHeight(tab.Top + mousePosition.Y - tab.Height / 2, tab.Height));
                        break;
                    }
                case TabAlignment.Right: {
                    location = new Point(this.Width - tab.Width,
                                         KeepInHostHeight(tab.Top + mousePosition.Y - tab.Height / 2, tab.Height));
                    break;
                }
            }

            // return the location in screen coordinates
            return this.PointToScreen(location);
        }
        public void Add(string tabText)
        {
            TabItem tab = new TabItem();
            tab.TabText = tabText;

            Add(tab);
        }
Exemple #22
0
        private void InsertTabAt(TabItem tab, int index)
        {
            int oldIndex = tabs.IndexOf(tab);
            int newIndex = index;

            tabs.RemoveAt(oldIndex);

            if(newIndex > oldIndex) {
                tabs.Insert(index - 1, tab);
            }
            else {
                tabs.Insert(index, tab);
            }

            // force relayout
            Relayout();
        }
 public bool Contains(TabItem tab)
 {
     return innerList.Contains(tab);
 }
Exemple #24
0
        private Point MousePositionToHost(TabItem tab, Point mousePosition)
        {
            Point location = mousePosition;

            if((_tabAlignment == TabAlignment.Top) ||
               (_tabAlignment == TabAlignment.Bottom)) {
                location = new Point(mousePosition.X + tab.Left,
                                     mousePosition.Y);
            }
            else {
                location = new Point(mousePosition.X,
                                     mousePosition.Y + tab.Top);
            }

            return location;
        }
 public void Insert(int index, TabItem tab)
 {
     innerList.Insert(index, tab);
     owner.ItemListChanged(tab, false);
 }
 public bool Contains(TabItem tab)
 {
     return(innerList.Contains(tab));
 }
 public int IndexOf(TabItem tab)
 {
     return(innerList.IndexOf(tab));
 }
Exemple #28
0
        public void ItemListChanged(TabItem item, bool remove)
        {
            if(remove) {
                // remove from control list
                Controls.Remove(item);
            }
            else {
                item.Owner = this;

                // add to control list
                if(this.Controls.Contains(item) == false) {
                    this.Controls.Add(item);
                }

                this.PerformLayout();
            }

            LayoutTabs();
        }