using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Design;
using System.ComponentModel;
using FastReport.Utils;
namespace FastReport
{
///
/// Specifies an origin where the new objects inserted from.
///
public enum InsertFrom
{
///
/// Specifies that a new object was inserted from the "Objects" toolbar or "Insert" menu.
///
NewObject,
///
/// Specifies that a new object was dragged from the "Dictionary" window.
///
Dictionary,
///
/// Specifies that a new object was pasted from the clipboard.
///
Clipboard
}
partial class Base
{
#region Properties
///
/// Gets a value indicating whether the object is selected in the designer.
///
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual bool IsSelected
{
get { return Report != null && Report.Designer != null && Report.Designer.SelectedObjects.IndexOf(this) != -1; }
}
///
/// Gets a value indicating whether one of the object's parent is selected in the designer.
///
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsParentSelected
{
get
{
if (Report.Designer == null)
return false;
Base parent = Parent;
while (parent != null)
{
if (Report.Designer.SelectedObjects.IndexOf(parent) != -1)
return true;
parent = parent.Parent;
}
return false;
}
}
#endregion
#region Public Methods
///
/// Deletes the object in the designer.
///
///
/// This method is called when you delete the object in the designer.
/// Typically this method calls the method to delete the object and all
/// its children. You may override it to delete the object only, and keep children.
///
public virtual void Delete()
{
Dispose();
}
///
/// Called before inserting a new object in the designer.
///
///
/// Do not call this method directly. You may override it if you are developing a
/// new component for FastReport.
///
/// Some objects are registered in the designer several times with the same object
/// type, but different flags. For example, the
/// represents different shapes: rectangle, roundrect, ellipse and so on. All these
/// shapes are registered in the designer using flags (the last parameter in this
/// code):
///
/// RegisteredObjects.Add(typeof(ShapeObject), "ReportPage,Shapes", 108, "Objects,Shapes,Rectangle", 0);
/// RegisteredObjects.Add(typeof(ShapeObject), "ReportPage,Shapes", 109, "Objects,Shapes,RoundRectangle", 1);
/// RegisteredObjects.Add(typeof(ShapeObject), "ReportPage,Shapes", 110, "Objects,Shapes,Ellipse", 2);
///
/// When we put the "Ellipse" object on a band, the designer creates the
/// ShapeObject instance and calls its OnBeforeInsert method with
/// flags value set to 2. In turn, the OnBeforeInsert method converts the
/// int value of the flags to the shape kind:
///
/// public override void OnBeforeInsert(int flags)
/// {
/// FShape = (ShapeKind)flags;
/// }
///
///
///
/// Object's flags.
public virtual void OnBeforeInsert(int flags)
{
}
///
/// Called after the new object was inserted in the designer.
///
///
/// Do not call this method directly. You may override it if you are developing a new component
/// for FastReport.
/// This method is called when new object is inserted, pasted from clipboard or dragged from
/// "Dictionary" window. You may override this method if you need to perform some actions when object
/// is inserted. Typical implementation invokes the object's editor if "Edit after insert" flag is set
/// in the designer options.
///
/// The insertion source.
public virtual void OnAfterInsert(InsertFrom source)
{
}
///
/// Called when the user selects another object in the designer.
///
///
/// This method is typically used by the in-place object's editor to check if selection was changed and close
/// the editor.
///
public virtual void SelectionChanged()
{
}
///
/// Gets the object's context menu.
///
/// Null reference if object does not have a menu.
///
/// Do not call this method directly. You may override it if you are developing a new component
/// for FastReport.
/// You may use base menu classes such as ,
/// to create own context menus.
///
public virtual ContextMenuBase GetContextMenu()
{
return null;
}
///
/// Gets an image index for this component to display it in the Report Tree.
///
/// The image index or -1 if no image is associated with this component.
public virtual int GetImageIndex()
{
ObjectInfo objItem = RegisteredObjects.FindObject(this);
if (objItem != null)
return objItem.ImageIndex;
return -1;
}
#endregion
private string ExtractDefaultMacrosInternal(Dictionary macroValues, string text)
{
string[] copyNames = Report.PrintSettings.CopyNames;
string copyName = "";
if (copyNames.Length > 0)
{
// get zero-based index of printed copy. In the preview, use the first copy name
int copyIndex = 0;
if (macroValues.ContainsKey("Copy#"))
copyIndex = (int)macroValues["Copy#"];
// get appropriate copy name
if (copyIndex >= copyNames.Length)
copyIndex = copyNames.Length - 1;
copyName = copyNames[copyIndex];
}
return text.Replace("[COPYNAME#]", copyName);
}
}
}