tangxu
2024-10-11 e0b745b416843934dacfd4268da624595661004b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System.Drawing;
 
namespace System.Windows.Forms
{
    /// <summary>
    /// Helper functions for RTL and LTR layout
    /// </summary>
    public class LayoutHelper
    {
        private readonly Ribbon _ribbon;
 
        public LayoutHelper(Ribbon ribbon)
        {
            _ribbon = ribbon;
        }
 
        /// <summary>
        /// Layout position. Near to or further from the Ribbon Orb. 
        /// </summary>
        public enum RTLLayoutPosition
        {
            /// <summary>
            /// Closer to the Ribbon Orb (Left when not in RTL mode).
            /// </summary>
            Near,
            /// <summary>
            /// Further from the Ribbon Orb (right when in RTL mode).
            /// </summary>
            Far
        }
 
        /// <summary>
        /// Calculate the new horizontal position for a Rectangle against a given reference Rectangle.
        /// </summary>
        /// <param name="reference"></param>
        /// <param name="rect"></param>
        /// <param name="type"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public Rectangle CalcNewPosition(Rectangle reference, Rectangle rect, RTLLayoutPosition type, int distance)
        {
            if (((_ribbon.RightToLeft == RightToLeft.No) && (type == RTLLayoutPosition.Near)) || ((_ribbon.RightToLeft == RightToLeft.Yes) && (type == RTLLayoutPosition.Far)))
            {
                //Object on left
                return new Rectangle(reference.Left - distance - rect.Width, rect.Y, rect.Width, rect.Height);
            }
 
            //Object on right
            return new Rectangle(reference.Right + distance, rect.Y, rect.Width, rect.Height);
        }
 
        /// <summary>
        /// Calculate the new horizontal position for a Point against a given reference Rectangle.
        /// </summary>
        /// <param name="reference"></param>
        /// <param name="point"></param>
        /// <param name="type"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public Point CalcNewPosition(Rectangle reference, Point point, RTLLayoutPosition type, int distance)
        {
            if (((_ribbon.RightToLeft == RightToLeft.No) && (type == RTLLayoutPosition.Near)) || ((_ribbon.RightToLeft == RightToLeft.Yes) && (type == RTLLayoutPosition.Far)))
            {
                //Object on left
                return new Point(reference.Left - distance, point.Y);
            }
 
            //Object on right
            return new Point(reference.Right + distance, point.Y);
        }
 
        /// <summary>
        /// Calculate the new horizontal position for a Point against a given reference Rectangle.
        /// </summary>
        /// <param name="reference"></param>
        /// <param name="rect"></param>
        /// <param name="type"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public Rectangle CalcNewPosition(Point reference, Rectangle rect, RTLLayoutPosition type, int distance)
        {
            if (((_ribbon.RightToLeft == RightToLeft.No) && (type == RTLLayoutPosition.Near)) || ((_ribbon.RightToLeft == RightToLeft.Yes) && (type == RTLLayoutPosition.Far)))
            {
                //Object on left
                return new Rectangle(reference.X - distance - rect.Width, rect.Y, rect.Width, rect.Height);
            }
 
            //Object on right
            return new Rectangle(reference.X + distance, rect.Y, rect.Width, rect.Height);
        }
 
    }
}