Exemplo n.º 1
0
        /// <summary>
        /// Get corrected cursor coordinates relative to Visual</summary>
        /// <param name="relativeTo">Visual to get coordinates relative to</param>
        /// <returns>Cursor position in current coordinate system of the Visual</returns>
        public static Point CorrectGetPosition(Visual relativeTo)
        {
            var w32Mouse = new Windows.POINT();

            GetCursorPos(ref w32Mouse);
            return(relativeTo.PointFromScreen(new Point(w32Mouse.x, w32Mouse.y)));
        }
Exemplo n.º 2
0
        void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (Dispatcher.Thread != Thread.CurrentThread)
            {
                Dispatcher.BeginInvoke(new EventHandler <ElapsedEventArgs>(Timer_Elapsed), new object[] { sender, e });
                return;
            }
            try
            {
                Point curMousePos = m_lastItemOver != null?Win32Calls.GetPosition(m_lastItemOver) : new Point(-1, -1);

                if (m_lastItemOver != null && new Rect(0, 0, m_lastItemOver.ActualWidth, m_lastItemOver.ActualHeight).Contains(curMousePos))
                {
                    TimeSpan ts = DateTime.Now - m_timerTime;
                    if (ts.TotalMilliseconds > 500 || Mouse.LeftButton == MouseButtonState.Pressed)
                    {
                        ShowPopup();
                        m_lastItemOver.IsChecked = true;
                        m_lastItemOver           = null;
                        m_timerTime = DateTime.Now;
                    }
                    m_timer.Start();
                }
                else
                {
                    var app = Application.Current;
                    if (app == null)
                    {
                        return;
                    }

                    var window = app.MainWindow;
                    if (window == null || !window.IsActive)
                    {
                        return;
                    }

                    if (PART_Popup.IsOpen && !PART_Popup.Resizing)
                    {
                        var pt32 = new Windows.POINT();
                        Win32Calls.GetCursorPos(ref pt32);
                        Point  mousePos = new Point(pt32.x, pt32.y);
                        Point  pos      = PointToScreen(new Point(0, 0));
                        Matrix m        = PresentationSource.FromVisual(Window.GetWindow(this)).CompositionTarget.TransformToDevice;
                        if (m != Matrix.Identity)
                        {
                            m.Invert();
                            mousePos = m.Transform(mousePos);
                            pos      = m.Transform(pos);
                        }
                        switch (TabsPlacement)
                        {
                        case System.Windows.Controls.Dock.Top:
                            pos.Y += ActualHeight;
                            break;

                        case System.Windows.Controls.Dock.Bottom:
                            pos.Y -= PART_Popup.Height;
                            break;

                        case System.Windows.Controls.Dock.Left:
                            pos.X += ActualWidth;
                            break;

                        case System.Windows.Controls.Dock.Right:
                            pos.X -= PART_Popup.Width;
                            break;
                        }
                        bool  b2      = new Rect(pos.X, pos.Y, PART_Popup.Width, PART_Popup.Height).Contains(mousePos);
                        Point posThis = Win32Calls.GetPosition(this);
                        bool  b3      = new Rect(0, 0, ActualWidth, ActualHeight).Contains(posThis);
                        if (!b2 && !b3)
                        {
                            TimeSpan ts = DateTime.Now - m_timerTime;
                            if (ts.TotalMilliseconds > 1000)
                            {
                                // if mouse is outside for more than some time, then collapse this popup
                                ClosePopup();
                            }
                            else
                            {
                                m_timer.Start();
                            }
                        }
                        else
                        {
                            m_timerTime = DateTime.Now;
                            m_timer.Start();
                        }
                    }
                }
            }
            catch (InvalidOperationException)
            {
                // Can be thrown when closing the application and popup is still open...
            }
        }
Exemplo n.º 3
0
 private static extern bool GetCursorPos(ref Windows.POINT pt);
Exemplo n.º 4
0
 private static extern bool ScreenToClient(IntPtr hwnd, ref Windows.POINT pt);
Exemplo n.º 5
0
 internal static extern bool GetCursorPos(ref Windows.POINT pt);