Ejemplo n.º 1
0
            // This Present is used when we are using the expicit Show methods for 2.0.
            // It will not reposition the window.
            public void PresentModal(Control control, string text)
            {
                if (IsDisposed)
                {
                    return;
                }

                Size display_size;

                XplatUI.GetDisplaySize(out display_size);

                associated_control = control;

                Text = text;

                PopupEventArgs pea = new PopupEventArgs(control, control, false, Size.Empty);

                OnPopup(pea);

                if (pea.Cancel)
                {
                    return;
                }

                Size = pea.ToolTipSize;

                Visible = true;
            }
        public void Show(Point position, ToolStripDropDownDirection direction)
        {
            this.PerformLayout();

            Point show_point = CalculateShowPoint(position, direction, Size);

            if (this.Location != show_point)
            {
                this.Location = show_point;
            }

            // Prevents recursion
            if (Visible)
            {
                return;
            }

            CancelEventArgs e = new CancelEventArgs();

            this.OnOpening(e);

            if (e.Cancel)
            {
                return;
            }

            // The tracker lets us know when the form is clicked or loses focus
            ToolStripManager.AppClicked     += new EventHandler(ToolStripMenuTracker_AppClicked);
            ToolStripManager.AppFocusChange += new EventHandler(ToolStripMenuTracker_AppFocusChange);

            bool useNativeMenu = true;

            foreach (var item in this.Items)
            {
                useNativeMenu &= item is ToolStripMenuItem || item is ToolStripSeparator;
            }

            if (useNativeMenu)
            {
                currentMenu = ToNSMenu();
                ((MonoMenuDelegate)currentMenu.Delegate).BeforePopup();
                show_point = CalculateShowPoint(position, direction, new Size((int)currentMenu.Size.Width, (int)currentMenu.Size.Height));
                NSApplication.SharedApplication.BeginInvokeOnMainThread(delegate {
                    Size displaySize;
                    XplatUI.GetDisplaySize(out displaySize);
                    currentMenu.PopUpMenu(null, new CGPoint(show_point.X, displaySize.Height - show_point.Y), null);
                });
            }

            base.Show();

            ToolStripManager.SetActiveToolStrip(this, ToolStripManager.ActivatedByKeyboard);

            // Called from NSMenuDelegate for native menus
            if (!useNativeMenu)
            {
                this.OnOpened(EventArgs.Empty);
            }
        }
Ejemplo n.º 3
0
            public void Present(Control control, string text)
            {
                if (IsDisposed)
                {
                    return;
                }

                Size display_size;

                XplatUI.GetDisplaySize(out display_size);

                associated_control = control;

                Text = text;

                PopupEventArgs pea = new PopupEventArgs(control, control, false, Size.Empty);

                OnPopup(pea);

                if (pea.Cancel)
                {
                    return;
                }

                Size size = pea.ToolTipSize;

                Width  = size.Width;
                Height = size.Height;

                int cursor_w, cursor_h, hot_x, hot_y;

                XplatUI.GetCursorInfo(control.Cursor.Handle, out cursor_w, out cursor_h, out hot_x, out hot_y);
                Point loc = Control.MousePosition;

                loc.Y += (cursor_h - hot_y);

                if ((loc.X + Width) > display_size.Width)
                {
                    loc.X = display_size.Width - Width;
                }

                if ((loc.Y + Height) > display_size.Height)
                {
                    loc.Y = Control.MousePosition.Y - Height - hot_y;
                }

                Location = loc;
                Visible  = true;
                BringToFront();
            }
Ejemplo n.º 4
0
        private void ShowInternal(Control control, Point screenPosition, ToolStripDropDownDirection direction)
        {
            this.PerformLayout();

            Point show_point = CalculateShowPoint(screenPosition, direction, Size);

            if (this.Location != show_point)
            {
                this.Location = show_point;
            }

            // Prevents recursion
            if (Visible)
            {
                return;
            }

            SetSourceControl(control);

            CancelEventArgs e = new CancelEventArgs();

            this.OnOpening(e);

            if (e.Cancel)
            {
                return;
            }

            // The tracker lets us know when the form is clicked or loses focus
            ToolStripManager.AppClicked     += new EventHandler(ToolStripMenuTracker_AppClicked);
            ToolStripManager.AppFocusChange += new EventHandler(ToolStripMenuTracker_AppFocusChange);

            bool useNativeMenu = true;

            foreach (var item in this.Items)
            {
                useNativeMenu &= item is ToolStripMenuItem || item is ToolStripSeparator;
            }

            // Prevent closing native menus by the Application object - it would be too early, in MouseDown.
            // Native menus will close automatically, *after MouseUp*. This way, we can handle both
            // ways of selecting the item: mouse_down-move-mouse_up and click-move-click.
            ToolStripManager.DismissingHandledNatively = useNativeMenu;

#if XAMARINMAC
            if (useNativeMenu)
            {
                currentMenu = ToNSMenu();
                ((MonoMenuDelegate)currentMenu.Delegate).BeforePopup();
                show_point = CalculateShowPoint(screenPosition, direction, new Size((int)currentMenu.Size.Width, (int)currentMenu.Size.Height));
                PostMouseUp(control, show_point);
                NSApplication.SharedApplication.BeginInvokeOnMainThread(delegate {
                    if (control != null)
                    {
                        var winPosition = control.PointToClient(show_point);
                        currentMenu.PopUpMenu(null, new CGPoint(winPosition.X, winPosition.Y), control.Handle.ToNSView());
                    }
                    else
                    {
                        Size displaySize;
                        XplatUI.GetDisplaySize(out displaySize);
                        currentMenu.PopUpMenu(null, new CGPoint(show_point.X, displaySize.Height - show_point.Y), null);
                    }
                });
            }
#endif

            base.Show();

            ToolStripManager.SetActiveToolStrip(this, ToolStripManager.ActivatedByKeyboard);

            // Called from NSMenuDelegate for native menus
            if (!useNativeMenu)
            {
                this.OnOpened(EventArgs.Empty);
            }
        }