コード例 #1
0
        public static bool IsPressed(this IPopupItem item)
        {
            var uip = item as UIElement;

            if (uip == null)
            {
                return(false);
            }

            Func <bool> keyPressed = () => {
                if (!uip.IsFocused)
                {
                    return(false);
                }
                return(Keyboard.IsKeyDown(Key.Enter) || Keyboard.IsKeyDown(Key.Space));
            };
            Func <bool> mousePressed = () =>
            {
                if (!uip.IsMouseOver)
                {
                    return(false);
                }
                return(Mouse.PrimaryDevice.Captured == uip);
            };

            return(keyPressed() || mousePressed());
        }
コード例 #2
0
        void PathDiff(IPopupItem oldValue, IPopupItem newValue, PTarget target)
        {
            GetPath(oldPath, oldValue);
            GetPath(newPath, newValue);

            oldPath.Where(x => !newPath.Contains(x)).ForEach(p =>
            {
                switch (target)
                {
                case PTarget.Highlight:
                    p.IsHighlighted = false;
                    break;

                case PTarget.Open:
                    p.IsOpen = false;
                    break;
                }
            });
            newPath.ForEach(p =>
            {
                switch (target)
                {
                case PTarget.Highlight:
                    p.IsHighlighted = true;
                    break;

                case PTarget.Open:
                    p.IsOpen = true;
                    break;
                }
            });
        }
コード例 #3
0
        public static IPopupItem NavigateItem(this IPopupItem item, bool openChildren = true)
        {
            if (item == null)
            {
                return(null);
            }
            if (item is IPopupRoot)
            {
                ((IPopupRoot)item).PopupManager.Tracking = false;
                if (!((DependencyObject)item).IsInMainFocusScope())
                {
                    Keyboard.Focus(null);
                }
                return(null);
            }
            var c = item.FirstFocusableElement();

            if (c == null)
            {
                return(null);
            }

            var pm = item.PopupRoot.PopupManager;

            pm.OpenedItem = (!openChildren || item.ParentItem() != null) ? item.ParentItem() : item;
            c.Focus();
            return(item);
        }
コード例 #4
0
ファイル: MenuRibbon.cs プロジェクト: pentest30/MenuRibbon
        protected override void OnPreviewMouseWheel(MouseWheelEventArgs e)
        {
            if (PopupManager.Tracking || IsPinning)
            {
                cumulativeWheelDelta += e.Delta;
                if (Math.Abs(cumulativeWheelDelta) > MouseWheelSelectionChangeThreshold)
                {
                    bool forward = cumulativeWheelDelta < 0;
                    cumulativeWheelDelta = 0;

                    IPopupItem selected = null;
                    if (PopupManager.Tracking)
                    {
                        if (PopupManager.HighlightedItem != null)
                        {
                            var p = PopupManager.HighlightedItem;
                            while (p.ParentItem != null)
                            {
                                p = p.ParentItem;
                            }
                            selected = p;
                        }
                    }
                    else
                    {
                        var item = PinnedItem;
                        selected = IsItemItsOwnContainer(item) ? (IPopupItem)item : (IPopupItem)ItemContainerGenerator.ContainerFromItem(item);
                    }

                    IPopupItem next = null;
                    if (selected != null)
                    {
                        next = selected
                               .PopupSiblings(forward, false)
                               .Where(x => PopupManager.Tracking || x is RibbonItem)
                               .FirstOrDefault();
                    }
                    else
                    {
                        next = this.PopupChildren()
                               .Where(x => PopupManager.Tracking || x is RibbonItem)
                               .FirstOrDefault();
                    }

                    if (next != null && next != selected)
                    {
                        e.Handled = true;
                        if (PopupManager.Tracking)
                        {
                            PopupManager.Enter(next, true);
                        }
                        else
                        {
                            PinnedItem = ItemContainerGenerator.ItemFromContainer((DependencyObject)next);
                        }
                    }
                }
            }
            base.OnPreviewMouseWheel(e);
        }
コード例 #5
0
 public void Exit(IPopupItem p)
 {
     if (p == HighlightedItem)
     {
         HighlightedItem = p.ParentItem;
     }
 }
コード例 #6
0
 void OnLater()
 {
     if (laterItem == HighlightedItem)
     {
         OpenedItem = HighlightedItem;
     }
     laterItem = null;
 }
コード例 #7
0
 void GetPath(List <IPopupItem> list, IPopupItem p)
 {
     list.Clear();
     while (p != null)
     {
         list.Insert(0, p);
         p = p.ParentItem;
     }
 }
コード例 #8
0
ファイル: BrowsingPopup.cs プロジェクト: glupschta/Kex
 private void SetGridSelection(IPopupItem selection)
 {
     var item = selection as IItem;
     if (item != null)
     {
         ListerManager.Instance.CommandManager.CurrentItem = item;
         Keyboard.Focus(Input.TextBox);
     }
 }
コード例 #9
0
 public static bool OnNavigateChildren(this IPopupItem item)
 {
     if (!item.HasItems())
     {
         return(false);
     }
     item.PopupRoot.PopupManager.OpenedItem = item;
     item.PopupChildren().SelectableItem().FirstOrDefault().NavigateItem();
     return(true);
 }
コード例 #10
0
        public static void CloseAllPopups(this IPopupItem item)
        {
            Action <DependencyObject> closeRoot = dp =>
            {
                var p = (IPopupRoot)dp;
                p.PopupManager.Tracking = false;
            };
            var dpitem = (DependencyObject)item;

            dpitem.VisualHierarchy().Where(x => x is IPopupRoot).ForEach(x => closeRoot(x));
            dpitem.LogicalHierarchy().Where(x => x is IPopupRoot).ForEach(x => closeRoot(x));
        }
コード例 #11
0
 public void Enter(IPopupItem p, bool forceNow = false)
 {
     if (forceNow)
     {
         HighlightedItem = p;
         OpenedItem      = p;
     }
     else
     {
         HighlightedItem = p;
         OpenLater(p);
     }
 }
コード例 #12
0
        public static IEnumerable <IPopupItem> PopupSiblings(this IPopupItem start, bool forward, bool cycle)
        {
            if (start.PopupRoot == start)
            {
                return(new IPopupItem[0]);
            }

            // MenuItemContainer need work around
            ItemsControl parent = null;

            foreach (var item in ((DependencyObject)start).VisualHierarchy().Skip(1))
            {
                if (item is ItemsControl)
                {
                    parent = (ItemsControl)item;
                    break;
                }
                else if (item is IPopupItem)
                {
                    start = (IPopupItem)item;
                }
            }
            if (parent == null || parent.Items.Count < 2)
            {
                return(new IPopupItem[0]);
            }

            var index = parent.ItemContainerGenerator.IndexFromContainer((DependencyObject)start);

            return(Enumerable.Range(1, parent.Items.Count)
                   .Select(x => forward ? index + x : index - x)
                   .Select(x =>
            {
                if (x < 0)
                {
                    return cycle ? x + parent.Items.Count : 0;
                }
                if (x > parent.Items.Count - 1)
                {
                    return cycle ? x - parent.Items.Count : parent.Items.Count - 1;
                }
                return x;
            })
                   .Distinct()
                   .Select(x => parent.Items[x])
                   .Select(x => parent.IsItemItsOwnContainer(x) ? x : parent.ItemContainerGenerator.ContainerFromItem(x))
                   .Where(x => x is IPopupItem)
                   .Select(x => (IPopupItem)x)
                   );
        }
コード例 #13
0
 public static IPopupItem ParentItem(this IPopupItem p)
 {
     // MenuItemContainer need work around
     if (p == null)
     {
         return(null);
     }
     // skip MenuItemContainer
     do
     {
         p = p.ParentItem;
     }while (p != null && !(p is ItemsControl));
     return(p);
 }
コード例 #14
0
 private void Popup_OnCloseRequested(PanelPopup sender, Control popupBase)
 {
     if (typeof(IPopupItem).IsAssignableFrom(sender.popup.GetType()))
     {
         IPopupItem item = (IPopupItem)sender.popup;
         if (!item.OnBeforePopupClose())
         {
             return;
         }
         item.OnPopupClose();
     }
     ChangePage(popupBase);
     RemovePage(sender, true);
 }
コード例 #15
0
ファイル: extensions.cs プロジェクト: ozay17/MusixClient
 public static void ClosePopup(this IPopupItem popup)
 {
     if (typeof(Control).IsAssignableFrom(popup.GetType()))
     {
         Control pc = (Control)popup;
         if (pc.Parent != null && pc.Parent is Panel pn)
         {
             if (pn.Parent != null && pn.Parent is PanelPopup popupItem)
             {
                 MainWindow.Instance.ClosePopup(popupItem);
             }
         }
     }
 }
コード例 #16
0
ファイル: BasePopupItem.cs プロジェクト: pentest30/MenuRibbon
        protected virtual void UpdateTopNRoot()
        {
            DependencyObject p   = this;
            IPopupItem       top = this;

            while (p != null && !(p is IPopupRoot))
            {
                p = p.VisualParent();
                if (p is IPopupItem)
                {
                    top = (IPopupItem)p;
                }
            }
            PopupRoot  = p as IPopupRoot;
            Top        = top;
            IsTopLevel = top == this;
        }
コード例 #17
0
 public static void OnKeyUpNavigate(this IPopupItem item, KeyEventArgs e)
 {
     if (!item.Handle(e))
     {
         return;
     }
     switch (e.Key)
     {
     case Key.Enter:
     case Key.Space:
         item.IsPressed = item.IsPressed();
         if (!item.IsPressed)
         {
             item.Action();
             e.Handled = true;
         }
         break;
     }
 }
コード例 #18
0
        public void ShowPopup(Control PopupItem)
        {
            Control popupBase = SelectedPage;

            if (popupBase != null)
            {
                PNContent.SuspendLayout();
                PanelPopup popup = new PanelPopup(popupBase, PopupItem);
                DoubleBuffered          = true;
                popup.OnCloseRequested += Popup_OnCloseRequested;
                if (typeof(IPopupItem).IsAssignableFrom(PopupItem.GetType()))
                {
                    IPopupItem item = (IPopupItem)PopupItem;
                    item.OnPopupOpen();
                }
                ChangePage(popup);
                PNContent.ResumeLayout();
            }
        }
コード例 #19
0
 static bool Handle(this IPopupItem item, KeyEventArgs e)
 {
     if (e.Handled && e.Key != Key.Escape)
     {
         return(false);
     }
     if (item.PopupRoot == null)
     {
         return(false);
     }
     if (e.OriginalSource is DependencyObject)
     {
         var dp = (DependencyObject)e.OriginalSource;
         if (!dp.VisualHierarchy()
             .TakeWhile(x => !(x is Window || x is Popup))
             .Contains((DependencyObject)item))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #20
0
		public void Enter(IPopupItem p, bool forceNow = false)
		{
			if (forceNow)
			{
				HighlightedItem = p;
				OpenedItem = p;
			}
			else
			{
				HighlightedItem = p;
				OpenLater(p);
			}
		}
コード例 #21
0
 public static IEnumerable <IPopupItem> PopupChildren(this IPopupItem parent)
 {
     return(PopupChildren(parent as ItemsControl));
 }
コード例 #22
0
 public static IPopupItem NavigateSibling(this IPopupItem item, bool forward, bool cycle)
 {
     return(item.PopupSiblings(forward, cycle).SelectableItem().FirstOrDefault().NavigateItem());
 }
コード例 #23
0
		void OnLater()
		{
			if (laterItem == HighlightedItem)
				OpenedItem = HighlightedItem;
			laterItem = null;
		}
コード例 #24
0
		public void OpenLater(IPopupItem p)
		{
			laterItem = p;
			Start();
		}
コード例 #25
0
		public void Close()
		{
			OpenedItem = null;
			HighlightedItem = null;
		}
コード例 #26
0
		public void Exit(IPopupItem p)
		{
			if (p == HighlightedItem)
				HighlightedItem = p.ParentItem;
		}
コード例 #27
0
        public static bool HasItems(this IPopupItem item)
        {
            var ic = item as ItemsControl;

            return(ic != null && ic.Items.Count > 0);
        }
コード例 #28
0
		void GetPath(List<IPopupItem> list, IPopupItem p)
		{
			list.Clear();
			while (p != null)
			{
				list.Insert(0, p);
				p = p.ParentItem;
			}
		}
コード例 #29
0
		void PathDiff(IPopupItem oldValue, IPopupItem newValue, PTarget target)
		{
			GetPath(oldPath, oldValue);
			GetPath(newPath, newValue);

			oldPath.Where(x => !newPath.Contains(x)).ForEach(p =>
			{
				switch (target)
				{
					case PTarget.Highlight:
						p.IsHighlighted = false;
						break;
					case PTarget.Open:
						p.IsOpen = false;
						break;
				}
			});
			newPath.ForEach(p =>
			{
				switch (target)
				{
					case PTarget.Highlight:
						p.IsHighlighted = true;
						break;
					case PTarget.Open:
						p.IsOpen = true;
						break;
				}
			});
		}
コード例 #30
0
        public static void OnKeyDownNavigate(this IPopupItem item, KeyEventArgs e)
        {
            if (!item.Handle(e))
            {
                return;
            }

            var key = e.Key;

            var fe = item as FrameworkElement;

            if (fe != null)
            {
                if (fe.FlowDirection == FlowDirection.RightToLeft)
                {
                    switch (key)
                    {
                    case Key.Right:
                        key = Key.Left;
                        break;

                    case Key.Left:
                        key = Key.Right;
                        break;
                    }
                }
            }

            var  pm     = item.PopupRoot.PopupManager;
            bool isRoot = item.ParentItem() == null;
            var  top    = item;

            while (top.ParentItem() != null)
            {
                top = top.ParentItem();
            }

            if (key == Key.Tab)
            {
                bool shift = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift;
                if (isRoot)
                {
                    key = shift ? Key.Left : Key.Right;
                }
                else
                {
                    key = shift ? Key.Up : Key.Down;
                }
            }

            switch (key)
            {
            case Key.Escape:
                if (isRoot)
                {
                    Keyboard.Focus(null);
                    e.Handled = true;
                }
                else
                {
                    e.Handled = null != item.ParentItem().NavigateItem(false);
                }
                break;

            case Key.Right:
                if (isRoot)
                {
                    e.Handled = null != item.NavigateSibling(true, true);
                }
                else
                {
                    if (item.HasItems())
                    {
                        item.OnNavigateChildren();
                        e.Handled = true;
                    }
                    else
                    {
                        pm.OpenedItem = top.NavigateSibling(true, true);
                        e.Handled     = null != pm.OpenedItem;
                    }
                }
                break;

            case Key.Left:
                if (isRoot)
                {
                    e.Handled = null != item.NavigateSibling(false, true);
                }
                else
                {
                    if (item.ParentItem() != top)
                    {
                        e.Handled = null != item.ParentItem().NavigateItem();
                    }
                    else
                    {
                        pm.OpenedItem = top.NavigateSibling(false, true);
                        e.Handled     = null != pm.OpenedItem;
                    }
                }
                break;

            case Key.Up:
                if (isRoot)
                {
                    e.Handled = item.OnNavigateChildren();
                }
                else
                {
                    e.Handled = null != item.NavigateSibling(false, true);
                }
                break;

            case Key.Down:
                if (isRoot)
                {
                    e.Handled = item.OnNavigateChildren();
                }
                else
                {
                    e.Handled = null != item.NavigateSibling(true, true);
                }
                break;

            case Key.Enter:
            case Key.Space:
                e.Handled      = true;
                item.IsPressed = true;
                break;
            }
        }
コード例 #31
0
 public void OpenLater(IPopupItem p)
 {
     laterItem = p;
     Start();
 }
コード例 #32
0
 public void Close()
 {
     OpenedItem      = null;
     HighlightedItem = null;
 }