Пример #1
0
        internal void EnsureVisibleBounds(Toplevel top, int x, int y, out int nx, out int ny)
        {
            nx = Math.Max(x, 0);
            nx = nx + top.Frame.Width > Driver.Cols ? Math.Max(Driver.Cols - top.Frame.Width, 0) : nx;
            bool m, s;

            if (SuperView == null || SuperView.GetType() != typeof(Toplevel))
            {
                m = Application.Top.MenuBar != null;
            }
            else
            {
                m = ((Toplevel)SuperView).MenuBar != null;
            }
            int l = m ? 1 : 0;

            ny = Math.Max(y, l);
            if (SuperView == null || SuperView.GetType() != typeof(Toplevel))
            {
                s = Application.Top.StatusBar != null;
            }
            else
            {
                s = ((Toplevel)SuperView).StatusBar != null;
            }
            l  = s ? Driver.Rows - 1 : Driver.Rows;
            ny = Math.Min(ny, l);
            ny = ny + top.Frame.Height > l?Math.Max(l - top.Frame.Height, m? 1 : 0) : ny;
        }
Пример #2
0
        /// <summary>
        /// Method invoked when a mouse event is generated
        /// </summary>
        /// <param name="mouseEvent"></param>
        /// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
        public override bool OnMouseEvent(MouseEvent mouseEvent)
        {
            MouseEventArgs args = new MouseEventArgs(mouseEvent);

            MouseClick?.Invoke(args);
            if (args.Handled)
            {
                return(true);
            }
            if (MouseEvent(mouseEvent))
            {
                return(true);
            }


            if (mouseEvent.Flags == MouseFlags.Button1Clicked)
            {
                if (!HasFocus && SuperView != null)
                {
                    SuperView.SetFocus(this);
                    SetNeedsDisplay();
                }

                Clicked?.Invoke();
                return(true);
            }
            return(false);
        }
Пример #3
0
        public override bool MouseEvent(MouseEvent ev)
        {
            if (!ev.Flags.HasFlag(MouseFlags.Button1Clicked))
            {
                return(false);
            }
            if (!HasFocus)
            {
                SuperView.SetFocus(this);
            }

            var point = ev.X;

            if (point > FieldLen)
            {
                point = FieldLen;
            }
            if (point < 1)
            {
                point = 1;
            }
            CursorPosition = point;
            AdjCursorPosition();
            return(true);
        }
Пример #4
0
 internal void CloseMenu()
 {
     selected = -1;
     SetNeedsDisplay();
     SuperView.Remove(openMenu);
     previousFocused?.SuperView?.SetFocus(previousFocused);
     openMenu = null;
 }
Пример #5
0
        private void Search_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.MouseEvent.Flags != MouseFlags.Button1Clicked)
            {
                return;
            }

            SuperView.SetFocus((View)sender);
        }
Пример #6
0
        internal void OpenMenu(int index, int sIndex = -1, MenuBarItem subMenu = null)
        {
            isMenuOpening = true;
            OnOpenMenu?.Invoke(this, null);
            int pos = 0;

            switch (subMenu)
            {
            case null:
                lastFocused = lastFocused ?? SuperView.MostFocused;
                if (openSubMenu != null)
                {
                    CloseMenu(false, true);
                }
                if (openMenu != null)
                {
                    SuperView.Remove(openMenu);
                }

                for (int i = 0; i < index; i++)
                {
                    pos += Menus [i].Title.Length + 2;
                }
                openMenu        = new Menu(this, pos, 1, Menus [index]);
                openCurrentMenu = openMenu;
                openCurrentMenu.previousSubFocused = openMenu;

                SuperView.Add(openMenu);
                SuperView.SetFocus(openMenu);
                break;

            default:
                if (openSubMenu == null)
                {
                    openSubMenu = new List <Menu> ();
                }
                if (sIndex > -1)
                {
                    RemoveSubMenu(sIndex);
                }
                else
                {
                    var last = openSubMenu.Count > 0 ? openSubMenu.Last() : openMenu;
                    openCurrentMenu = new Menu(this, last.Frame.Left + last.Frame.Width, last.Frame.Top + 1 + last.current, subMenu);
                    openCurrentMenu.previousSubFocused = last.previousSubFocused;
                    openSubMenu.Add(openCurrentMenu);
                    SuperView.Add(openCurrentMenu);
                }
                selectedSub = openSubMenu.Count - 1;
                SuperView?.SetFocus(openCurrentMenu);
                break;
            }
            isMenuOpening = false;
            isMenuClosed  = false;
            MenuOpen      = true;
        }
Пример #7
0
 internal void RemoveAllOpensSubMenus()
 {
     if (openSubMenu != null)
     {
         foreach (var item in openSubMenu)
         {
             SuperView.Remove(item);
         }
     }
 }
Пример #8
0
        internal void CloseMenu(bool reopen = false, bool isSubMenu = false)
        {
            isMenuClosing = true;
            OnCloseMenu?.Invoke(this, null);
            switch (isSubMenu)
            {
            case false:
                if (openMenu != null)
                {
                    SuperView.Remove(openMenu);
                }
                SetNeedsDisplay();
                if (previousFocused != null && openMenu != null && previousFocused.ToString() != openCurrentMenu.ToString())
                {
                    previousFocused?.SuperView?.SetFocus(previousFocused);
                }
                openMenu = null;
                if (lastFocused is Menu)
                {
                    lastFocused = null;
                }
                LastFocused = lastFocused;
                lastFocused = null;
                if (LastFocused != null)
                {
                    if (!reopen)
                    {
                        selected = -1;
                    }
                    LastFocused.SuperView?.SetFocus(LastFocused);
                }
                else
                {
                    SuperView.SetFocus(this);
                    isMenuClosed = true;
                    PositionCursor();
                }
                isMenuClosed = true;
                break;

            case true:
                selectedSub = -1;
                SetNeedsDisplay();
                RemoveAllOpensSubMenus();
                openCurrentMenu.previousSubFocused?.SuperView?.SetFocus(openCurrentMenu.previousSubFocused);
                openSubMenu = null;
                break;
            }
            isMenuClosing = false;
            MenuOpen      = false;
        }
Пример #9
0
        void RemoveSubMenu(int index)
        {
            if (openSubMenu == null)
            {
                return;
            }
            for (int i = openSubMenu.Count - 1; i > index; i--)
            {
                isMenuClosing = true;
                if (openSubMenu.Count - 1 > 0)
                {
                    SuperView.SetFocus(openSubMenu [i - 1]);
                }
                else
                {
                    SuperView.SetFocus(openMenu);
                }
                if (openSubMenu != null)
                {
                    SuperView.Remove(openSubMenu [i]);
                    openSubMenu.Remove(openSubMenu [i]);
                }
                RemoveSubMenu(i);
            }
            if (openSubMenu.Count > 0)
            {
                openCurrentMenu = openSubMenu.Last();
            }

            //if (openMenu.Subviews.Count == 0)
            //	return;
            //if (index == 0) {
            //	//SuperView.SetFocus (previousSubFocused);
            //	FocusPrev ();
            //	return;
            //}

            //for (int i = openMenu.Subviews.Count - 1; i > index; i--) {
            //	isMenuClosing = true;
            //	if (openMenu.Subviews.Count - 1 > 0)
            //		SuperView.SetFocus (openMenu.Subviews [i - 1]);
            //	else
            //		SuperView.SetFocus (openMenu);
            //	if (openMenu != null) {
            //		Remove (openMenu.Subviews [i]);
            //		openMenu.Remove (openMenu.Subviews [i]);
            //	}
            //	RemoveSubMenu (i);
            //}
            isMenuClosing = false;
        }
Пример #10
0
        ///<inheritdoc/>
        public override bool MouseEvent(MouseEvent me)
        {
            if (!me.Flags.HasFlag(MouseFlags.Button1Clicked))
            {
                return(false);
            }

            SuperView.SetFocus(this);
            var previousChecked = Checked;

            Checked = !Checked;
            OnToggled(previousChecked);
            SetNeedsDisplay();

            return(true);
        }
Пример #11
0
        /// <summary>
        /// Track Alt key-up events. On Windows, when a user releases Alt (without another key), the menu gets focus but doesn't open.
        /// We mimic that behavior here.
        /// </summary>
        /// <param name="keyEvent"></param>
        /// <returns></returns>
        public override bool KeyUp(KeyEvent keyEvent)
        {
            if (keyEvent.IsAlt)
            {
                // User pressed Alt - this may be a precursor to a menu accelerator (e.g. Alt-F)
                if (!keyEvent.IsCtrl && openedByAltKey && isMenuClosed && openMenu == null && ((uint)keyEvent.Key & (uint)Key.CharMask) == 0)
                {
                    // There's no open menu, the first menu item should be highlight.
                    // The right way to do this is to SetFocus(MenuBar), but for some reason
                    // that faults.

                    //Activate (0);
                    //StartMenu ();
                    isMenuClosed = false;
                    selected     = 0;
                    CanFocus     = true;
                    lastFocused  = SuperView.MostFocused;
                    SuperView.SetFocus(this);
                    SetNeedsDisplay();
                    Application.GrabMouse(this);
                }
                else if (!openedByHotKey)
                {
                    // There's an open menu. If this Alt key-up is a pre-cursor to an accelerator
                    // we don't want to close the menu because it'll flash.
                    // How to deal with that?

                    if (openMenu != null)
                    {
                        CloseAllMenus();
                    }
                    openedByAltKey = false;
                    isMenuClosed   = true;
                    selected       = -1;
                    CanFocus       = false;
                    if (lastFocused != null)
                    {
                        SuperView?.SetFocus(lastFocused);
                    }
                    SetNeedsDisplay();
                    Application.UngrabMouse();
                }

                return(true);
            }
            return(false);
        }
Пример #12
0
        public override bool MouseEvent(MouseEvent me)
        {
            if (!me.Flags.HasFlag(MouseFlags.Button1Clicked))
            {
                return(false);
            }

            SuperView.SetFocus(this);
            Checked = !Checked;
            SetNeedsDisplay();

            if (Toggled != null)
            {
                Toggled(this, EventArgs.Empty);
            }
            return(true);
        }
Пример #13
0
        void OpenMenu(int index)
        {
            if (openMenu != null)
            {
                SuperView.Remove(openMenu);
            }

            int pos = 0;

            for (int i = 0; i < index; i++)
            {
                pos += Menus [i].Title.Length + 3;
            }

            openMenu = new Menu(this, pos, 1, Menus [index]);

            SuperView.Add(openMenu);
            SuperView.SetFocus(openMenu);
        }
Пример #14
0
        void FocusNearestView(IEnumerable <View> views, Direction direction)
        {
            if (views == null)
            {
                return;
            }

            bool found          = false;
            bool focusProcessed = false;
            int  idx            = 0;

            foreach (var v in views)
            {
                if (v == this)
                {
                    found = true;
                }
                if (found && v != this)
                {
                    if (direction == Direction.Forward)
                    {
                        SuperView?.FocusNext();
                    }
                    else
                    {
                        SuperView?.FocusPrev();
                    }
                    focusProcessed = true;
                    if (SuperView.Focused != null && SuperView.Focused != this)
                    {
                        return;
                    }
                }
                else if (found && !focusProcessed && idx == views.Count() - 1)
                {
                    views.ToList() [0].SetFocus();
                }
                idx++;
            }
        }
Пример #15
0
        ///<inheritdoc/>
        public override bool MouseEvent(MouseEvent mouseEvent)
        {
            // FIXED:The code is currently disabled, because the
            // Driver.UncookMouse does not seem to have an effect if there is
            // a pending mouse event activated.

            int nx, ny;

            if (!dragPosition.HasValue && mouseEvent.Flags == (MouseFlags.Button1Pressed))
            {
                // Only start grabbing if the user clicks on the title bar.
                if (mouseEvent.Y == 0)
                {
                    start        = new Point(mouseEvent.X, mouseEvent.Y);
                    dragPosition = new Point();
                    nx           = mouseEvent.X - mouseEvent.OfX;
                    ny           = mouseEvent.Y - mouseEvent.OfY;
                    dragPosition = new Point(nx, ny);
                    SuperView?.BringSubviewToFront(this);
                    Application.GrabMouse(this);
                }

                //System.Diagnostics.Debug.WriteLine ($"Starting at {dragPosition}");
                return(true);
            }
            else if (mouseEvent.Flags == (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition) ||
                     mouseEvent.Flags == MouseFlags.Button3Pressed)
            {
                if (dragPosition.HasValue)
                {
                    if (SuperView == null)
                    {
                        // Redraw the entire app window using just our Frame. Since we are
                        // Application.Top, and our Frame always == our Bounds (Location is always (0,0))
                        // our Frame is actually view-relative (which is what Redraw takes).
                        // We need to pass all the view bounds because since the windows was
                        // moved around, we don't know exactly what was the affected region.
                        Application.Top.SetNeedsDisplay();
                    }
                    else
                    {
                        SuperView.SetNeedsDisplay();
                    }
                    EnsureVisibleBounds(this, mouseEvent.X + (SuperView == null ? mouseEvent.OfX - start.X : Frame.X - start.X),
                                        mouseEvent.Y + (SuperView == null ? mouseEvent.OfY : Frame.Y),
                                        out nx, out ny, out _, out _);

                    dragPosition = new Point(nx, ny);
                    LayoutSubviews();
                    Frame = new Rect(nx, ny, Frame.Width, Frame.Height);
                    if (X == null || X is Pos.PosAbsolute)
                    {
                        X = nx;
                    }
                    if (Y == null || Y is Pos.PosAbsolute)
                    {
                        Y = ny;
                    }
                    //System.Diagnostics.Debug.WriteLine ($"nx:{nx},ny:{ny}");

                    // FIXED: optimize, only SetNeedsDisplay on the before/after regions.
                    SetNeedsDisplay();
                    return(true);
                }
            }

            if (mouseEvent.Flags == MouseFlags.Button1Released && dragPosition.HasValue)
            {
                Application.UngrabMouse();
                Driver.UncookMouse();
                dragPosition = null;
            }

            //System.Diagnostics.Debug.WriteLine (mouseEvent.ToString ());
            return(false);
        }
        void ReleaseDesignerOutlets()
        {
            if (connectButton != null)
            {
                connectButton.Dispose();
                connectButton = null;
            }

            if (inputContainer != null)
            {
                inputContainer.Dispose();
                inputContainer = null;
            }

            if (lineView != null)
            {
                lineView.Dispose();
                lineView = null;
            }

            if (logoIV != null)
            {
                logoIV.Dispose();
                logoIV = null;
            }

            if (qrButton != null)
            {
                qrButton.Dispose();
                qrButton = null;
            }

            if (Right_Bottom != null)
            {
                Right_Bottom.Dispose();
                Right_Bottom = null;
            }

            if (setting_icon != null)
            {
                setting_icon.Dispose();
                setting_icon = null;
            }

            if (SuperView != null)
            {
                SuperView.Dispose();
                SuperView = null;
            }

            if (Top_Center != null)
            {
                Top_Center.Dispose();
                Top_Center = null;
            }

            if (url_TextField != null)
            {
                url_TextField.Dispose();
                url_TextField = null;
            }

            if (urlView != null)
            {
                urlView.Dispose();
                urlView = null;
            }

            if (zone_logo != null)
            {
                zone_logo.Dispose();
                zone_logo = null;
            }

            if (zone_logo_View != null)
            {
                zone_logo_View.Dispose();
                zone_logo_View = null;
            }
        }
Пример #17
0
        internal void EnsureVisibleBounds(Toplevel top, int x, int y, out int nx, out int ny)
        {
            nx = Math.Max(x, 0);
            int l;

            if (SuperView == null || SuperView is Toplevel)
            {
                l = Driver.Cols;
            }
            else
            {
                l = SuperView.Frame.Width;
            }
            nx = nx + top.Frame.Width > l?Math.Max(l - top.Frame.Width, 0) : nx;

            SetWidth(top.Frame.Width, out int rWidth);
            if (rWidth < 0 && nx >= top.Frame.X)
            {
                nx = Math.Max(top.Frame.Right - 2, 0);
            }
            //System.Diagnostics.Debug.WriteLine ($"nx:{nx}, rWidth:{rWidth}");
            bool m, s;

            if (SuperView == null || SuperView.GetType() != typeof(Toplevel))
            {
                m = Application.Top.MenuBar != null;
            }
            else
            {
                m = ((Toplevel)SuperView).MenuBar != null;
            }
            if (SuperView == null || SuperView is Toplevel)
            {
                l = m ? 1 : 0;
            }
            else
            {
                l = 0;
            }
            ny = Math.Max(y, l);
            if (SuperView == null || SuperView.GetType() != typeof(Toplevel))
            {
                s = Application.Top.StatusBar != null && Application.Top.StatusBar.Visible;
            }
            else
            {
                s = ((Toplevel)SuperView).StatusBar != null && ((Toplevel)SuperView).StatusBar.Visible;
            }
            if (SuperView == null || SuperView is Toplevel)
            {
                l = s ? Driver.Rows - 1 : Driver.Rows;
            }
            else
            {
                l = s ? SuperView.Frame.Height - 1 : SuperView.Frame.Height;
            }
            ny = Math.Min(ny, l);
            ny = ny + top.Frame.Height > l?Math.Max(l - top.Frame.Height, m? 1 : 0) : ny;

            SetHeight(top.Frame.Height, out int rHeight);
            if (rHeight < 0 && ny >= top.Frame.Y)
            {
                ny = Math.Max(top.Frame.Bottom - 2, 0);
            }
            //System.Diagnostics.Debug.WriteLine ($"ny:{ny}, rHeight:{rHeight}");
        }