예제 #1
0
        /// <summary>
        /// Gets item rectangle in WPF logical pixel units.
        /// </summary>
        /// <exception cref="IndexOutOfRangeException"></exception>
        public Rect GetRectLogical(int index, TVParts parts = 0, bool inScreen = false, bool clampX = false)
        {
            var    r = GetRectPhysical(index, parts, inScreen, clampX);
            double f = 96d / _dpi;

            return(new Rect(r.left * f, r.top * f, r.Width * f, r.Height * f));
        }
예제 #2
0
        /// <summary>
        /// Gets item rectangle in physical pixel units.
        /// Horizontally the rectangle is limited to the visible area.
        /// </summary>
        /// <exception cref="IndexOutOfRangeException"></exception>
        /// <exception cref="InvalidOperationException">Control not created.</exception>
        public RECT GetRectPhysical(int index, TVParts parts = 0, bool inScreen = false, bool clampX = false)
        {
            if (!_IsValid(index))
            {
                throw new IndexOutOfRangeException();
            }
            if (!_hasHwnd)
            {
                throw new InvalidOperationException();
            }
            int y = _ItemTop(index);
            var r = new RECT(0, y, _width, _itemHeight);

            if (parts != 0)
            {
                _GetPartOffsets(index, out var k);
                //left
                if (parts.Has(TVParts.Left))
                {
                    r.left = k.left;
                }
                else if (parts.Has(TVParts.Checkbox))
                {
                    r.left = k.checkbox;
                }
                else if (parts.Has(TVParts.MarginLeft))
                {
                    r.left = k.marginLeft;
                }
                else if (parts.Has(TVParts.Image))
                {
                    r.left = k.image;
                }
                else if (parts.Has(TVParts.Text))
                {
                    r.left = k.text;
                }
                else if (parts.Has(TVParts.MarginRight))
                {
                    r.left = k.marginRight;
                }
                else
                {
                    r.left = k.right;
                }
                //right
                if (parts.Has(TVParts.Right))
                {
                    r.right = Math.Max(k.right, _width);
                }
                else if (parts.Has(TVParts.MarginRight))
                {
                    r.right = k.right;
                }
                else if (parts.Has(TVParts.Text))
                {
                    r.right = k.marginRight;
                }
                else if (parts.Has(TVParts.Image))
                {
                    r.right = k.text;
                }
                else if (parts.Has(TVParts.MarginLeft))
                {
                    r.right = k.image;
                }
                else if (parts.Has(TVParts.Checkbox))
                {
                    r.right = k.marginLeft;
                }
                else
                {
                    r.right = k.checkbox;
                }
                //clamp
                if (clampX)
                {
                    r.left  = Math.Clamp(r.left, 0, _width);
                    r.right = Math.Clamp(r.right, 0, _width);
                }
            }
            else if (!clampX)
            {
                r.left  = -_hscroll.Offset;
                r.right = Math.Max(_width, _itemsWidth - r.left);
            }
            if (inScreen)
            {
                _w.MapClientToScreen(ref r);
            }
            return(r);
        }