Ejemplo n.º 1
0
        internal ContentWindow(TabberItem item, Rect rect, bool firstDrag = false)
        {
            inDrag         = false;
            iniRect        = rect;
            this.firstDrag = firstDrag;
            (item.Parent as TabberControl).Items.Remove(item);
            tabberControl = new TabberControl();
            tabberControl.Items.Add(item);
            Content = tabberControl;
            if (firstDrag)
            {
                WindowStyle        = WindowStyle.None;
                AllowsTransparency = true;
                background         = Background;
                Background         = Brushes.Transparent;
                Top = rect.Y;
            }
            else
            {
                Top = rect.Y - SystemParameters.WindowCaptionHeight;
                Top = Top < 0 ? 0 : Top;
            }
            Left   = rect.X;
            Width  = rect.Width;
            Height = rect.Height;

            Check           += ContentWindow_Check;
            Closed          += ContentWindow_Closed;
            LocationChanged += ContentWindow_LocationChanged;
        }
Ejemplo n.º 2
0
        internal void SortPins()
        {
            if (firstSort)
            {
                return;
            }

            TabberItem selectedItem = (TabberItem)SelectedItem;

            for (int i = 1; i <= Items.Count; i++)
            {
                for (int j = 0; j < Items.Count - i; j++)
                {
                    if (!(Items[j] as TabberItem).Pin &&
                        (Items[j + 1] as TabberItem).Pin)
                    {
                        object nextTemp = Items[j + 1];
                        Items.Remove(nextTemp);
                        Items.Insert(j, nextTemp);
                    }
                }
            }
            if (selectedItem == null && Items.Count > 0)
            {
                (Items[0] as TabberItem).IsSelected = true;
            }
            else if (Items.Count > 0)
            {
                selectedItem.IsSelected = true;
            }
        }
Ejemplo n.º 3
0
        internal void Over(ContentWindow window)
        {
            if (object.ReferenceEquals(window, currentWindow))
            {
                return;
            }

            if (mainTabberIsEmpty)
            {
                if (shadowItem != null)
                {
                    ZOrders.OrderFound();
                    int dropItemIndex = Items.IndexOf(shadowItem);
                    Items.Remove(shadowItem);
                    TabberItem replacedItem = window.ReplaceItem();
                    InsertTab(dropItemIndex, replacedItem);
                    currentWindow.Activate();
                }
            }
            else
            {
                if (shadowItem != null)
                {
                    ZOrders.OrderFound();
                    int dropItemIndex = Items.IndexOf(shadowItem);
                    Items.Remove(shadowItem);
                    TabberItem replacedItem = window.ReplaceItem();
                    InsertTab(dropItemIndex, replacedItem);
                    currentWindow.Activate();
                }
            }
        }
Ejemplo n.º 4
0
        internal Point GetDragPosition()
        {
            TabberItem item = GetDragItem();
            Point      locationFromScreen = item.PointToScreen(
                new Point(item.ActualWidth / 2, item.ActualHeight / 2));

            return(locationFromScreen);
        }
Ejemplo n.º 5
0
        private void FakeTab(Point drahPosition)
        {
            TabItem replaceItem = null;

            foreach (TabItem tab in Items)
            {
                Rect tabRect = TabItemRect(tab);
                if (tabRect.Contains(drahPosition))
                {
                    replaceItem = tab;
                    break;
                }
            }
            if (replaceItem != null)
            {
                TabberItem tabberItem = replaceItem as TabberItem;
                if (tabberItem != null && !tabberItem.Pin && (oldReplaceItem == null || !oldReplaceItem.Equals(replaceItem)))
                {
                    oldReplaceItem = replaceItem;
                    int shadowIndex = shadowItem != null?Items.IndexOf(shadowItem) : -1;

                    if (shadowItem == null)
                    {
                        shadowItem        = new ShadowTabberItem();
                        shadowItem.Header = new string(' ', 24);
                    }
                    int replaceItemIndex = Items.IndexOf(replaceItem);

                    if (shadowIndex > -1 && shadowIndex < replaceItemIndex)
                    {
                        Items.Remove(replaceItem);
                        Items.Insert(shadowIndex, replaceItem);
                    }
                    else
                    {
                        Items.Remove(shadowItem);
                        Items.Insert(replaceItemIndex, shadowItem);
                    }
                    shadowItem.IsSelected = true;
                }
            }
            else if ((Items[Items.Count - 1] as ShadowTabberItem) == null)
            {
                if (shadowItem == null)
                {
                    shadowItem        = new ShadowTabberItem();
                    shadowItem.Header = new string(' ', 24);
                    Items.Add(shadowItem);
                }
                else
                {
                    Items.Remove(shadowItem);
                    Items.Add(shadowItem);
                }
                oldReplaceItem        = null;
                shadowItem.IsSelected = true;
            }
        }
Ejemplo n.º 6
0
        internal TabberItem ReplaceItem()
        {
            TabberItem item = (TabberItem)tabberControl.Items[0];

            tabberControl.Items.Remove(item);
            Hide();
            Close();
            return(item);
        }
Ejemplo n.º 7
0
        private void InsertTab(int index, TabberItem item)
        {
            TabberItem newItem = new TabberItem();

            newItem.DataContext = item.DataContext;
            newItem.Header      = item.Header;
            newItem.Content     = item.Content;
            Items.Insert(index, newItem);
            newItem.IsSelected = true;
        }
Ejemplo n.º 8
0
 private void DragEnd()
 {
     foreach (TabberControl tabberControl in TabberControl.ZOrders)
     {
         tabberControl.Over(this);
     }
     inDrag = false;
     if (firstDrag)
     {
         if (tabberControl.Items.Count == 1)
         {
             TabberItem    item      = (TabberItem)tabberControl.Items[0];
             ContentWindow newWindow = new ContentWindow(
                 item,
                 new Rect(Left, Top, ActualWidth, ActualHeight),
                 false);
             Hide();
             newWindow.Show();
             newWindow.Activate();
             Close();
         }
     }
     firstDrag = false;
 }
Ejemplo n.º 9
0
        private void TabberItem_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed && dragTabAndWindow)
            {
                Window        currentWindow = Window.GetWindow(this);
                TabberControl tabberControl = (TabberControl)Parent;
                if (!((currentWindow as ContentWindow) == null &&
                      tabberControl.Items.Count < 2 &&
                      tabberControl.Pinned))
                {
                    Point innerMousePosition = Mouse.GetPosition(this);

                    if (moveEnter)
                    {
                        if (tabberControl.TabStripPlacement == Dock.Top || tabberControl.TabStripPlacement == Dock.Bottom)
                        {
                            #region Drag Section
                            if (((innerMousePosition.Y <= 0 || innerMousePosition.Y >= ActualHeight) &&
                                 (innerMousePosition.X > 0 && innerMousePosition.X < ActualWidth)) ||
                                (tabberControl.Items[0].Equals(this) && innerMousePosition.X <= 0) ||
                                (tabberControl.Items[tabberControl.Items.Count - 1].Equals(this) && innerMousePosition.X >= ActualWidth))
                            {
                                if (IsMouseCaptured)
                                {
                                    Mouse.Capture(null);
                                }

                                DragPressed?.Invoke(this, new EventArgs());
                                Point dragPosition = this.PointToScreen(innerMousePosition);
                                Pin    = false;
                                window = new ContentWindow(
                                    this,
                                    new Rect(
                                        dragPosition.X + (-ActualWidth / 2),
                                        dragPosition.Y + (-ActualHeight / 2),
                                        currentWindow.ActualWidth,
                                        currentWindow.ActualHeight),
                                    true);
                                dragTabAndWindow = false;
                                inDragMove       = true;
                                window.DragMove();
                                DragReleased?.Invoke(this, new EventArgs());
                            }
                            #endregion
                            #region Swap Section
                            else if (!tabberControl.Items[0].Equals(this) && innerMousePosition.X <= 0)
                            {
                                int        index    = tabberControl.Items.IndexOf(this);
                                TabberItem swapItem = (TabberItem)tabberControl.Items[index - 1];
                                if (swapItem.Pin == Pin)
                                {
                                    tabberControl.Items.Remove(swapItem);
                                    tabberControl.Items.Insert(index, swapItem);
                                }
                            }
                            else if (!tabberControl.Items[tabberControl.Items.Count - 1].Equals(this) && innerMousePosition.X >= ActualWidth)
                            {
                                int        index    = tabberControl.Items.IndexOf(this);
                                TabberItem swapItem = (TabberItem)tabberControl.Items[index + 1];
                                if (swapItem.Pin == Pin)
                                {
                                    tabberControl.Items.Remove(swapItem);
                                    tabberControl.Items.Insert(index, swapItem);
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            #region Drag Section
                            if (((innerMousePosition.X <= 0 || innerMousePosition.X >= ActualWidth) &&
                                 (innerMousePosition.Y > 0 && innerMousePosition.Y < ActualHeight)) ||
                                (tabberControl.Items[0].Equals(this) && innerMousePosition.Y <= 0) ||
                                (tabberControl.Items[tabberControl.Items.Count - 1].Equals(this) && innerMousePosition.Y >= ActualHeight))
                            {
                                if (IsMouseCaptured)
                                {
                                    Mouse.Capture(null);
                                }

                                DragPressed?.Invoke(this, new EventArgs());
                                Point dragPosition = this.PointToScreen(innerMousePosition);
                                Pin    = false;
                                window = new ContentWindow(
                                    this,
                                    new Rect(
                                        dragPosition.X + (-ActualWidth / 2),
                                        dragPosition.Y + (-ActualHeight / 2),
                                        currentWindow.ActualWidth,
                                        currentWindow.ActualHeight),
                                    true);
                                dragTabAndWindow = false;
                                inDragMove       = true;
                                window.DragMove();
                                DragReleased?.Invoke(this, new EventArgs());
                            }
                            #endregion
                            #region Swap Section
                            else if (!tabberControl.Items[0].Equals(this) && innerMousePosition.Y <= 0)
                            {
                                int        index    = tabberControl.Items.IndexOf(this);
                                TabberItem swapItem = (TabberItem)tabberControl.Items[index - 1];
                                if (swapItem.Pin == Pin)
                                {
                                    tabberControl.Items.Remove(swapItem);
                                    tabberControl.Items.Insert(index, swapItem);
                                }
                            }
                            else if (!tabberControl.Items[tabberControl.Items.Count - 1].Equals(this) && innerMousePosition.Y >= ActualHeight)
                            {
                                int        index    = tabberControl.Items.IndexOf(this);
                                TabberItem swapItem = (TabberItem)tabberControl.Items[index + 1];
                                if (swapItem.Pin == Pin)
                                {
                                    tabberControl.Items.Remove(swapItem);
                                    tabberControl.Items.Insert(index, swapItem);
                                }
                            }
                            #endregion
                        }
                    }
                    moveEnter = TabItemLocalRect().Contains(Mouse.GetPosition(this));
                }
            }
            else if (e.LeftButton == MouseButtonState.Released)
            {
                if (IsMouseCaptured && !inDragMove)
                {
                    Mouse.Capture(null);
                }
            }
        }