Esempio n. 1
0
        NcHitTest HandleNcHitTest(Point screenPoint)
        {
            var windowPoint = this.PointFromScreen(screenPoint);

            NcHitTest hit = NcHitTest.HTCLIENT;

            if (_contentWindow != null &&
                (_contentWindow.ResizeMode == System.Windows.ResizeMode.CanResize ||
                 _contentWindow.ResizeMode == System.Windows.ResizeMode.CanResizeWithGrip))
            {
                var chrome = _contentWindow.GetValue(Chrome.ChromeProperty) as Chrome;
                hit = NcBorderHitTest(chrome.ResizeBorderThickness, windowPoint);
            }
            //Debug.WriteLine(hit);
            return(hit);
        }
Esempio n. 2
0
        private NcHitTest HandleNcHitTest(IntPtr hWnd, IntPtr lParam)
        {
            Point screenPoint = lParam.ToPoint();
            Point windowPoint = ContentWindow.PointFromScreen(screenPoint);
            var   capH        = (double)WindowCaptionHeightConverter.Instance.Convert(Chrome.GetCaptionHeight(ContentWindow), typeof(Double), null, CultureInfo.CurrentCulture);
            //double capH = (windowCapH > -1 ? windowCapH : ContentWindow.ActualHeight);

            NcHitTest location = NcHitTest.HTCLIENT;
            var       hitTest  = ContentWindow.InputHitTest(windowPoint);

            if (hitTest != null && (windowPoint.Y <= capH || Chrome.GetIsCaption(hitTest)) &&
                !Chrome.GetIsHitTestVisible(hitTest))
            {
                location = NcHitTest.HTCAPTION;
                if (windowPoint.Y <= 40)
                {
                    // check for sysmenu style
                    if (((WindowStyles)User32.GetWindowLong(hWndContent, CommonWin32.WindowClasses.WindowLong.GWL_STYLE)).HasFlag(WindowStyles.WS_SYSMENU))
                    {
                        if (ContentWindow.FlowDirection == System.Windows.FlowDirection.LeftToRight)
                        {
                            if (windowPoint.X <= 40)
                            {
                                location = NcHitTest.HTSYSMENU;
                            }
                        }
                        else if (windowPoint.X >= (ContentWindow.ActualWidth - 40))
                        {
                            location = NcHitTest.HTSYSMENU;
                        }
                    }
                }
            }

            if (_resizeGrip != null && _resizeGrip.Visibility == System.Windows.Visibility.Visible &&
                VisualTreeHelper.HitTest(_resizeGrip, _resizeGrip.PointFromScreen(screenPoint)) != null)
            {
                location = _resizeGrip.FlowDirection == System.Windows.FlowDirection.LeftToRight ?
                           NcHitTest.HTBOTTOMRIGHT : NcHitTest.HTBOTTOMLEFT;
            }

            //Debug.WriteLine(location);
            return(location);
        }
Esempio n. 3
0
        NcHitTest HandleNcHitTest(Point screenPoint)
        {
            var windowPoint = _contentWindow.PointFromScreen(screenPoint);
            var capH        = (double)WindowCaptionHeightConverter.Instance.Convert(Chrome.GetCaptionHeight(_contentWindow), typeof(Double), null, CultureInfo.CurrentCulture);
            //double capH = (windowCapH > -1 ? windowCapH : _contentWindow.ActualHeight);

            NcHitTest location = NcHitTest.HTCLIENT;
            var       hitTest  = _contentWindow.InputHitTest(windowPoint);

            if (hitTest != null && (windowPoint.Y <= capH || Chrome.GetIsCaption(hitTest)) &&
                !Chrome.GetIsHitTestVisible(hitTest))
            {
                location = NcHitTest.HTCAPTION;
                if (windowPoint.Y <= 40)
                {
                    // TODO: check for sysmenu style
                    if (_contentWindow.FlowDirection == System.Windows.FlowDirection.LeftToRight)
                    {
                        if (windowPoint.X <= 40)
                        {
                            location = NcHitTest.HTSYSMENU;
                        }
                    }
                    else if (windowPoint.X >= (_contentWindow.ActualWidth - 40))
                    {
                        location = NcHitTest.HTSYSMENU;
                    }
                }
            }

            if (_resizeGrip != null && _resizeGrip.Visibility == System.Windows.Visibility.Visible &&
                VisualTreeHelper.HitTest(_resizeGrip, _resizeGrip.PointFromScreen(screenPoint)) != null)
            {
                location = _resizeGrip.FlowDirection == System.Windows.FlowDirection.LeftToRight ?
                           NcHitTest.HTBOTTOMRIGHT : NcHitTest.HTBOTTOMLEFT;
            }

            //Debug.WriteLine(location);
            return(location);
        }
Esempio n. 4
0
        IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            IntPtr retVal = IntPtr.Zero;

            if (!handled)
            {
                var wmsg = (WindowMessage)msg;
                //Debug.WriteLine(wmsg);
                switch (wmsg)
                {
                case WindowMessage.WM_NCCALCSIZE:
                    handled = true;
                    break;

                case WindowMessage.WM_NCHITTEST:
                    NcHitTest res = NcHitTest.HTBORDER;
                    if (_manager.ContentWindow.ResizeMode == ResizeMode.CanResizeWithGrip ||
                        _manager.ContentWindow.ResizeMode == ResizeMode.CanResize)
                    {
                        var pt       = PointFromScreen(lParam.ToPoint());
                        int diagSize = (int)(2 * PadSize);
                        switch (Side)
                        {
                        case BorderSide.Left:
                            if (pt.Y <= diagSize)
                            {
                                res = NcHitTest.HTTOPLEFT;
                            }
                            else if (pt.Y >= Height - diagSize)
                            {
                                res = NcHitTest.HTBOTTOMLEFT;
                            }
                            else
                            {
                                res = NcHitTest.HTLEFT;
                            }
                            break;

                        case BorderSide.Top:
                            if (pt.X <= diagSize)
                            {
                                res = NcHitTest.HTTOPLEFT;
                            }
                            else if (pt.X >= Width - diagSize)
                            {
                                res = NcHitTest.HTTOPRIGHT;
                            }
                            else
                            {
                                res = NcHitTest.HTTOP;
                            }
                            break;

                        case BorderSide.Right:
                            if (pt.Y <= diagSize)
                            {
                                res = NcHitTest.HTTOPRIGHT;
                            }
                            else if (pt.Y >= Height - diagSize)
                            {
                                res = NcHitTest.HTBOTTOMRIGHT;
                            }
                            else
                            {
                                res = NcHitTest.HTRIGHT;
                            }
                            break;

                        case BorderSide.Bottom:
                            if (pt.X <= diagSize)
                            {
                                res = NcHitTest.HTBOTTOMLEFT;
                            }
                            else if (pt.X >= Width - diagSize)
                            {
                                res = NcHitTest.HTBOTTOMRIGHT;
                            }
                            else
                            {
                                res = NcHitTest.HTBOTTOM;
                            }
                            break;
                        }
                    }
                    retVal  = new IntPtr((int)res);
                    handled = true;
                    break;

                case WindowMessage.WM_NCRBUTTONDOWN:
                case WindowMessage.WM_NCMBUTTONDOWN:
                case WindowMessage.WM_NCRBUTTONDBLCLK:
                case WindowMessage.WM_NCMBUTTONDBLCLK:
                case WindowMessage.WM_RBUTTONDBLCLK:
                case WindowMessage.WM_MBUTTONDBLCLK:
                case WindowMessage.WM_LBUTTONDBLCLK:
                    handled = true;
                    User32.SetForegroundWindow(_manager.hWndContent);
                    break;

                case WindowMessage.WM_NCLBUTTONDOWN:
                case WindowMessage.WM_NCLBUTTONDBLCLK:
                    handled = true;
                    // pass resizer msg to the content window instead
                    User32.SetForegroundWindow(_manager.hWndContent);
                    User32.SendMessage(_manager.hWndContent, (uint)msg, wParam, lParam);
                    break;

                case WindowMessage.WM_MOUSEACTIVATE:
                    var lowword = 0xffff & lParam.ToInt32();
                    var hchit   = (NcHitTest)lowword;

                    // in case of non-resizable window eat this msg
                    if (hchit == NcHitTest.HTCLIENT)
                    {
                        retVal = new IntPtr((int)MouseActivate.MA_NOACTIVATEANDEAT);
                    }
                    else
                    {
                        retVal = new IntPtr((int)MouseActivate.MA_NOACTIVATE);
                    }
                    handled = true;
                    break;

                case WindowMessage.WM_GETMINMAXINFO:
                    // overridden so max size = normal max + resize border (for when content window is max size without maximizing)
                    var thick = 2 * (int)PadSize;

                    MINMAXINFO para = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
                    var        orig = para.ptMaxTrackSize;
                    orig.x += thick;
                    orig.y += thick;
                    para.ptMaxTrackSize = orig;
                    Marshal.StructureToPtr(para, lParam, true);
                    break;
                }
            }
            return(retVal);
        }
 private void OnNcHitTest(IntPtr handledWindow, IntPtr firstParameter, IntPtr secondParameter)
 {
     NcHitTest?.Invoke(handledWindow, firstParameter, secondParameter);
 }