using System.Drawing;
namespace System.Windows.Forms
{
///
/// Helper functions for RTL and LTR layout
///
public class LayoutHelper
{
private readonly Ribbon _ribbon;
public LayoutHelper(Ribbon ribbon)
{
_ribbon = ribbon;
}
///
/// Layout position. Near to or further from the Ribbon Orb.
///
public enum RTLLayoutPosition
{
///
/// Closer to the Ribbon Orb (Left when not in RTL mode).
///
Near,
///
/// Further from the Ribbon Orb (right when in RTL mode).
///
Far
}
///
/// Calculate the new horizontal position for a Rectangle against a given reference Rectangle.
///
///
///
///
///
///
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);
}
///
/// Calculate the new horizontal position for a Point against a given reference Rectangle.
///
///
///
///
///
///
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);
}
///
/// Calculate the new horizontal position for a Point against a given reference Rectangle.
///
///
///
///
///
///
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);
}
}
}