using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using FastReport.Design;
using FastReport.Format;
using FastReport.Forms;
using System.Windows.Forms;
namespace FastReport
{
///
/// Holds the list of objects currently selected in the designer.
///
///
/// This class is used by the "Text" toolbar. Use methods of this class to perform some
/// operations on the selected objects.
/// Note: after calling any method in this class, call the
/// Designer.SetModified method to reflect changes.
/// Note: this list contains only objects of type. If you want to access all
/// selected objects, use the property.
///
public class SelectedTextObjects
{
private List list;
private Designer designer;
///
/// Gets the first selected object.
///
public TextObject First
{
get { return list.Count > 0 ? list[0] : null; }
}
///
/// Gets the number of selected objects.
///
public int Count
{
get { return list.Count; }
}
///
/// Gets a value indicating whether the operations are enabled.
///
public bool Enabled
{
get
{
return Count > 1 || (Count == 1 && CanModify(First));
}
}
private List ModifyList
{
get { return list.FindAll(CanModify); }
}
private bool CanModify(TextObject c)
{
return !c.HasRestriction(Restrictions.DontModify);
}
internal void Update()
{
list.Clear();
if (designer.SelectedObjects != null)
{
foreach (Base c in designer.SelectedObjects)
{
if (c is TextObject)
list.Add(c as TextObject);
}
}
}
///
/// Sets the font name for the selected objects.
///
/// Font name.
public void SetFontName(string name)
{
foreach (TextObject text in ModifyList)
{
text.Font = new Font(name, text.Font.Size, text.Font.Style);
}
designer.LastFormatting.Font = First.Font;
designer.SetModified();
}
///
/// Sets the font size for the selected objects.
///
/// Font size.
public void SetFontSize(float size)
{
foreach (TextObject text in ModifyList)
{
text.Font = new Font(text.Font.Name, size, text.Font.Style);
}
designer.LastFormatting.Font = First.Font;
designer.SetModified();
}
///
/// Toggles the specified font style for the selected objects.
///
/// Font style.
/// Toggle value.
public void ToggleFontStyle(FontStyle style, bool toggle)
{
foreach (TextObject text in ModifyList)
{
FontStyle newStyle = text.Font.Style;
if (toggle)
newStyle |= style;
else
newStyle &= ~style;
// some fonts do not support particular styles
try
{
text.Font = new Font(text.Font, newStyle);
}
catch
{
}
}
designer.LastFormatting.Font = First.Font;
designer.SetModified();
}
///
/// Sets the horizontal text alignment for tthe selected objects.
///
/// Alignment to set.
public void SetHAlign(HorzAlign align)
{
foreach (TextObject text in ModifyList)
{
text.HorzAlign = align;
}
designer.LastFormatting.HorzAlign = align;
designer.SetModified();
}
///
/// Sets the vertical text alignment for tthe selected objects.
///
/// Alignment to set.
public void SetVAlign(VertAlign align)
{
foreach (TextObject text in ModifyList)
{
text.VertAlign = align;
}
designer.LastFormatting.VertAlign = align;
designer.SetModified();
}
///
/// Sets the text color for the selected objects.
///
/// Text color.
public void SetTextColor(Color color)
{
foreach (TextObject text in ModifyList)
{
text.TextFill = new SolidFill(color);
}
designer.LastFormatting.TextFill = new SolidFill(color);
designer.SetModified();
}
///
/// Sets the angle for the selected objects.
///
/// Angle to set.
public void SetAngle(int angle)
{
foreach (TextObject text in ModifyList)
{
text.Angle = angle;
}
designer.LastFormatting.Angle = angle;
designer.SetModified();
}
///
/// Sets the AutoWidth property value for the selected objects.
///
/// Value to set.
public void SetAutoWidth(bool value)
{
foreach (TextObject text in ModifyList)
{
text.AutoWidth = value;
}
designer.SetModified();
}
///
/// Sets the WordWrap property value for the selected objects.
///
/// Value to set.
public void SetWordWrap(bool value)
{
foreach (TextObject text in ModifyList)
{
text.WordWrap = value;
}
designer.SetModified();
}
///
/// Sets the highlight conditions for the selected objects.
///
/// Highlight conditions.
public void SetConditions(ConditionCollection value)
{
foreach (TextObject text in ModifyList)
{
text.Highlight.Assign(value);
}
designer.SetModified();
}
///
/// Clears the text of the selected objects.
///
public void ClearText()
{
foreach (TextObject text in ModifyList)
{
text.Text = "";
}
designer.SetModified();
}
///
/// Invokes the highlight editor for the selected objects.
///
/// true if editor was closed with the OK button.
public bool InvokeHighlightEditor()
{
using (HighlightEditorForm form = new HighlightEditorForm(designer.ActiveReport))
{
form.Conditions = First.Highlight;
if (form.ShowDialog() == DialogResult.OK)
{
SetConditions(form.Conditions);
return true;
}
}
return false;
}
internal SelectedTextObjects(Designer designer)
{
this.designer = designer;
list = new List();
}
}
}