FastReport
1120 строк · 38.2 Кб
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.ComponentModel;
5using FastReport.Utils;
6using System.Windows.Forms;
7using System.Drawing.Design;
8
9namespace FastReport
10{
11/// <summary>
12/// The automatic shift mode.
13/// </summary>
14public enum ShiftMode
15{
16/// <summary>
17/// Do not shift the object.
18/// </summary>
19Never,
20
21/// <summary>
22/// Shift the object up or down if any object above it shrinks or grows.
23/// </summary>
24Always,
25
26/// <summary>
27/// Shift the object up or down if any object above it shrinks or grows.
28/// Objects must have overlapped x-coordinates.
29/// </summary>
30WhenOverlapped
31}
32
33/// <summary>
34/// Specifies where to print an object.
35/// </summary>
36[Flags]
37[TypeConverter(typeof(FastReport.TypeConverters.FlagConverter))]
38public enum PrintOn
39{
40/// <summary>
41/// Do not print the object.
42/// </summary>
43None = 0,
44
45/// <summary>
46/// Print the object on the first page. If this flag is not set, the object will not
47/// be printed on the first page.
48/// </summary>
49FirstPage = 1,
50
51/// <summary>
52/// Print the object on the last page. If this flag is not set, the object will not
53/// be printed on the last page. You should set the report's double pass option to make
54/// it work correctly.
55/// </summary>
56LastPage = 2,
57
58/// <summary>
59/// Print the object on odd pages only.
60/// </summary>
61OddPages = 4,
62
63/// <summary>
64/// Print the object on even pages only.
65/// </summary>
66EvenPages = 8,
67
68/// <summary>
69/// Print the object on band with "Repeat on Every Page" flag when that band is repeated.
70/// </summary>
71RepeatedBand = 16,
72
73/// <summary>
74/// Print the object if the report has single page only.
75/// </summary>
76SinglePage = 32
77}
78
79
80/// <summary>
81/// Specifies the style properties to use when style is applied.
82/// </summary>
83public enum StylePriority
84{
85/// <summary>
86/// Use the fill property of the style.
87/// </summary>
88UseFill,
89
90/// <summary>
91/// Use all style properties.
92/// </summary>
93UseAll
94}
95
96/// <summary>
97/// Base class for all report objects.
98/// </summary>
99public abstract partial class ReportComponentBase : ComponentBase
100{
101#region Fields
102private bool exportable;
103private string exportableExpression;
104private Border border;
105private FillBase fill;
106private string bookmark;
107private Hyperlink hyperlink;
108private bool canGrow;
109private bool canShrink;
110private bool growToBottom;
111private ShiftMode shiftMode;
112private string style;
113private string evenStyle;
114private string hoverStyle;
115private StylePriority evenStylePriority;
116private bool pageBreak;
117private PrintOn printOn;
118private string beforePrintEvent;
119private string afterPrintEvent;
120private string afterDataEvent;
121private string clickEvent;
122private bool flagSimpleBorder;
123private bool flagUseBorder;
124private bool flagUseFill;
125private bool flagPreviewVisible;
126private bool flagSerializeStyle;
127private bool flagProvidesHyperlinkValue;
128private RectangleF savedBounds;
129private bool savedVisible;
130private string savedBookmark;
131private Border savedBorder;
132private FillBase savedFill;
133private Cursor cursor;
134private string mouseMoveEvent;
135private string mouseUpEvent;
136private string mouseDownEvent;
137private string mouseEnterEvent;
138private string mouseLeaveEvent;
139#endregion
140
141#region Properties
142/// <summary>
143/// This event occurs before the object is added to the preview pages.
144/// </summary>
145public event EventHandler BeforePrint;
146
147/// <summary>
148/// This event occurs after the object was added to the preview pages.
149/// </summary>
150public event EventHandler AfterPrint;
151
152/// <summary>
153/// This event occurs after the object was filled with data.
154/// </summary>
155public event EventHandler AfterData;
156
157/// <summary>
158/// This event occurs when the user clicks the object in the preview window.
159/// </summary>
160public event EventHandler Click;
161
162/// <summary>
163/// Gets or sets a value that determines if the object can be exported.
164/// </summary>
165[DefaultValue(true)]
166[Category("Behavior")]
167public bool Exportable
168{
169get { return exportable; }
170set { exportable = value; }
171}
172
173/// <summary>
174/// Gets or sets a string containing expression that determines should be object exported.
175/// </summary>
176[DefaultValue("")]
177[Category("Behavior")]
178[Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
179public virtual string ExportableExpression
180{
181get { return exportableExpression; }
182set { exportableExpression = value; }
183}
184
185/// <summary>
186/// Gets or sets an object's border.
187/// </summary>
188[Category("Appearance")]
189public virtual Border Border
190{
191get { return border; }
192set
193{
194border = value;
195if (!String.IsNullOrEmpty(Style))
196Style = "";
197}
198}
199
200/// <summary>
201/// Gets or sets an object's fill.
202/// </summary>
203/// <remarks>
204/// The fill can be one of the following types: <see cref="SolidFill"/>, <see cref="LinearGradientFill"/>,
205/// <see cref="PathGradientFill"/>, <see cref="HatchFill"/>.
206/// <para/>To set the solid fill color, use the simpler <see cref="FillColor"/> property.
207/// </remarks>
208/// <example>This example shows how to set the new fill and change its properties:
209/// <code>
210/// textObject1.Fill = new SolidFill(Color.Green);
211/// (textObject1.Fill as SolidFill).Color = Color.Red;
212/// </code>
213/// </example>
214[Category("Appearance")]
215[EditorAttribute("FastReport.TypeEditors.FillEditor, FastReport", typeof(UITypeEditor))]
216public virtual FillBase Fill
217{
218get
219{
220return fill;
221}
222set
223{
224if (value == null)
225throw new ArgumentNullException("Fill");
226fill = value;
227if (!String.IsNullOrEmpty(Style))
228Style = "";
229}
230}
231
232/// <summary>
233/// Gets or sets the fill color in a simple manner.
234/// </summary>
235/// <remarks>
236/// This property can be used in a report script to change the fill color of the object. It is
237/// equivalent to: <code>reportComponent1.Fill = new SolidFill(color);</code>
238/// </remarks>
239[Browsable(false)]
240public Color FillColor
241{
242get { return Fill is SolidFill ? (Fill as SolidFill).Color : Color.Transparent; }
243set { Fill = new SolidFill(value); }
244}
245
246/// <summary>
247/// Gets or sets a bookmark expression.
248/// </summary>
249/// <remarks>
250/// This property can contain any valid expression that returns a bookmark name. This can be, for example,
251/// a data column. To navigate to a bookmark, you have to use the <see cref="Hyperlink"/> property.
252/// </remarks>
253
254[Category("Navigation")]
255[Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
256public string Bookmark
257{
258get { return bookmark; }
259set { bookmark = value; }
260}
261
262/// <summary>
263/// Gets or sets a hyperlink.
264/// </summary>
265/// <remarks>
266/// <para>The hyperlink is used to define clickable objects in the preview.
267/// When you click such object, you may navigate to the external url, the page number,
268/// the bookmark defined by other report object, or display the external report.
269/// Set the <b>Kind</b> property of the hyperlink to select appropriate behavior.</para>
270/// <para>Usually you should set the <b>Expression</b> property of the hyperlink to
271/// any valid expression that will be calculated when this object is about to print.
272/// The value of an expression will be used for navigation.</para>
273/// <para>If you want to navigate to
274/// something fixed (URL or page number, for example) you also may set the <b>Value</b>
275/// property instead of <b>Expression</b>.</para>
276/// </remarks>
277[Category("Navigation")]
278[Editor("FastReport.TypeEditors.HyperlinkEditor, FastReport", typeof(UITypeEditor))]
279public Hyperlink Hyperlink
280{
281get { return hyperlink; }
282set { hyperlink = value; }
283}
284
285/// <summary>
286/// Determines if the object can grow.
287/// </summary>
288/// <remarks>
289/// This property is applicable to the bands or text objects that can contain several text lines.
290/// If the property is set to <b>true</b>, object will grow to display all the information that it contains.
291/// </remarks>
292[DefaultValue(false)]
293[Category("Behavior")]
294public bool CanGrow
295{
296get { return canGrow; }
297set { canGrow = value; }
298}
299
300/// <summary>
301/// Determines if the object can shrink.
302/// </summary>
303/// <remarks>
304/// This property is applicable to the bands or text objects that can contain several text lines.
305/// If the property is set to true, object can shrink to remove the unused space.
306/// </remarks>
307[DefaultValue(false)]
308[Category("Behavior")]
309public bool CanShrink
310{
311get { return canShrink; }
312set { canShrink = value; }
313}
314
315/// <summary>
316/// Determines if the object must grow to the band's bottom side.
317/// </summary>
318/// <remarks>
319/// If the property is set to true, object grows to the bottom side of its parent. This is useful if
320/// you have several objects on a band, and some of them can grow or shrink.
321/// </remarks>
322[DefaultValue(false)]
323[Category("Behavior")]
324public bool GrowToBottom
325{
326get { return growToBottom; }
327set { growToBottom = value; }
328}
329
330/// <summary>
331/// Gets or sets a shift mode of the object.
332/// </summary>
333/// <remarks>
334/// See <see cref="FastReport.ShiftMode"/> enumeration for details.
335/// </remarks>
336[DefaultValue(ShiftMode.Always)]
337[Category("Behavior")]
338public ShiftMode ShiftMode
339{
340get { return shiftMode; }
341set { shiftMode = value; }
342}
343
344/// <summary>
345/// Gets or sets the style name.
346/// </summary>
347/// <remarks>
348/// Style is a set of common properties such as border, fill, font, text color. The <b>Report</b>
349/// has a set of styles in the <see cref="Report.Styles"/> property.
350/// </remarks>
351
352[Category("Appearance")]
353[Editor("FastReport.TypeEditors.StyleEditor, FastReport", typeof(UITypeEditor))]
354public string Style
355{
356get { return style; }
357set
358{
359ApplyStyle(value);
360style = value;
361}
362}
363
364/// <summary>
365/// Gets or sets a style name that will be applied to even band rows.
366/// </summary>
367/// <remarks>
368/// Style with this name must exist in the <see cref="Report.Styles"/> collection.
369/// </remarks>
370[Category("Appearance")]
371[Editor("FastReport.TypeEditors.StyleEditor, FastReport", typeof(UITypeEditor))]
372public string EvenStyle
373{
374get { return evenStyle; }
375set { evenStyle = value; }
376}
377
378/// <summary>
379/// Gets or sets a style name that will be applied to this object when the mouse pointer is over it.
380/// </summary>
381/// <remarks>
382/// Style with this name must exist in the <see cref="Report.Styles"/> collection.
383/// </remarks>
384
385[Category("Appearance")]
386[Editor("FastReport.TypeEditors.StyleEditor, FastReport", typeof(UITypeEditor))]
387public string HoverStyle
388{
389get { return hoverStyle; }
390set { hoverStyle = value; }
391}
392
393/// <summary>
394/// Gets or sets a value that determines which properties of the even style to use.
395/// </summary>
396/// <remarks>
397/// Usually you will need only the Fill property of the even style to be applied. If you want to
398/// apply all style settings, set this property to <b>StylePriority.UseAll</b>.
399/// </remarks>
400[DefaultValue(StylePriority.UseFill)]
401[Category("Appearance")]
402public StylePriority EvenStylePriority
403{
404get { return evenStylePriority; }
405set { evenStylePriority = value; }
406}
407
408/// <summary>
409/// Gets or sets a value that determines whether to insert the hard page break before processing this object.
410/// </summary>
411[Browsable(false)]
412[DefaultValue(false)]
413[Category("Behavior")]
414public bool PageBreak
415{
416get { return pageBreak; }
417set { pageBreak = value; }
418}
419
420/// <summary>
421/// Gets or sets a value that determines where to print the object.
422/// </summary>
423/// <remarks>
424/// See the <see cref="FastReport.PrintOn"/> enumeration for details.
425/// </remarks>
426[DefaultValue(PrintOn.FirstPage | PrintOn.LastPage | PrintOn.OddPages | PrintOn.EvenPages | PrintOn.RepeatedBand | PrintOn.SinglePage)]
427
428[Category("Behavior")]
429[Editor("FastReport.TypeEditors.FlagsEditor, FastReport", typeof(UITypeEditor))]
430public PrintOn PrintOn
431{
432get { return printOn; }
433set { printOn = value; }
434}
435
436/// <summary>
437/// Gets or sets a script event name that will be fired before the object will be printed in the preview page.
438/// </summary>
439[Category("Build")]
440public string BeforePrintEvent
441{
442get { return beforePrintEvent; }
443set { beforePrintEvent = value; }
444}
445
446/// <summary>
447/// Gets or sets a script event name that will be fired after the object was printed in the preview page.
448/// </summary>
449[Category("Build")]
450public string AfterPrintEvent
451{
452get { return afterPrintEvent; }
453set { afterPrintEvent = value; }
454}
455
456/// <summary>
457/// Gets or sets a script event name that will be fired after the object was filled with data.
458/// </summary>
459[Category("Build")]
460public string AfterDataEvent
461{
462get { return afterDataEvent; }
463set { afterDataEvent = value; }
464}
465
466/// <summary>
467/// Gets or sets a script event name that will be fired when the user click the object in the preview window.
468/// </summary>
469[Category("Preview")]
470public string ClickEvent
471{
472get { return clickEvent; }
473set { clickEvent = value; }
474}
475
476/// <summary>
477/// Determines if the object has custom border and use only <b>Border.Width</b>, <b>Border.Style</b> and
478/// <b>Border.Color</b> properties.
479/// </summary>
480/// <remarks>
481/// This flag is used to disable some toolbar buttons when such object is selected. Applicable to the
482/// ShapeObject and LineObject.
483/// </remarks>
484[Browsable(false)]
485public bool FlagSimpleBorder
486{
487get { return flagSimpleBorder; }
488set { flagSimpleBorder = value; }
489}
490
491/// <summary>
492/// Determines if the object uses the <b>Border</b>.
493/// </summary>
494/// <remarks>
495/// This flag is used to disable some toolbar buttons when such object is selected.
496/// </remarks>
497[Browsable(false)]
498public bool FlagUseBorder
499{
500get { return flagUseBorder; }
501set { flagUseBorder = value; }
502}
503
504/// <summary>
505/// Determines if the object uses the fill.
506/// </summary>
507/// <remarks>
508/// This flag is used to disable some toolbar buttons when such object is selected.
509/// </remarks>
510[Browsable(false)]
511public bool FlagUseFill
512{
513get { return flagUseFill; }
514set { flagUseFill = value; }
515}
516
517/// <summary>
518/// Gets or sets a value indicates that object should not be added to the preview.
519/// </summary>
520[Browsable(false)]
521public bool FlagPreviewVisible
522{
523get { return flagPreviewVisible; }
524set { flagPreviewVisible = value; }
525}
526
527/// <summary>
528/// Determines if serializing the Style property is needed.
529/// </summary>
530/// <remarks>
531/// The <b>Style</b> property must be serialized last. Some ancestor classes may turn off the standard Style
532/// serialization and serialize it by themselves.
533/// </remarks>
534[Browsable(false)]
535public bool FlagSerializeStyle
536{
537get { return flagSerializeStyle; }
538set { flagSerializeStyle = value; }
539}
540
541/// <summary>
542/// Determines if an object can provide the hyperlink value automatically.
543/// </summary>
544/// <remarks>
545/// This flag is used in complex objects such as Matrix or Chart. These objects can provide
546/// a hyperlink value automatically, depending on where you click.
547/// </remarks>
548[Browsable(false)]
549public bool FlagProvidesHyperlinkValue
550{
551get { return flagProvidesHyperlinkValue; }
552set { flagProvidesHyperlinkValue = value; }
553}
554
555/// <summary>
556/// Gets an object's parent band.
557/// </summary>
558internal BandBase Band
559{
560get
561{
562if (this is BandBase)
563return this as BandBase;
564
565Base c = Parent;
566while (c != null)
567{
568if (c is BandBase)
569return c as BandBase;
570c = c.Parent;
571}
572return null;
573}
574}
575
576/// <summary>
577/// Gets an object's parent data band.
578/// </summary>
579internal DataBand DataBand
580{
581get
582{
583if (this is DataBand)
584return this as DataBand;
585
586Base c = Parent;
587while (c != null)
588{
589if (c is DataBand)
590return c as DataBand;
591c = c.Parent;
592}
593
594ObjectCollection pageBands = Page.AllObjects;
595foreach (Base c1 in pageBands)
596{
597if (c1 is DataBand)
598return c1 as DataBand;
599}
600return null;
601}
602}
603
604[Browsable(false)]
605protected internal virtual bool IsCompilationNeeded => false;
606
607/// <summary>
608/// Gets or sets an object's cursor shape.
609/// </summary>
610/// <remarks>
611/// This property is used in the preview mode.
612/// </remarks>
613[Category("Appearance")]
614public Cursor Cursor
615{
616get { return cursor; }
617set { cursor = value; }
618}
619
620/// <summary>
621/// Gets or sets a script event name that will be fired when the user
622/// moves the mouse over the object in the preview window.
623/// </summary>
624[Category("Preview")]
625public string MouseMoveEvent
626{
627get { return mouseMoveEvent; }
628set { mouseMoveEvent = value; }
629}
630
631/// <summary>
632/// Gets or sets a script event name that will be fired when the user
633/// releases the mouse button in the preview window.
634/// </summary>
635[Category("Preview")]
636public string MouseUpEvent
637{
638get { return mouseUpEvent; }
639set { mouseUpEvent = value; }
640}
641
642/// <summary>
643/// Gets or sets a script event name that will be fired when the user
644/// clicks the mouse button in the preview window.
645/// </summary>
646[Category("Preview")]
647public string MouseDownEvent
648{
649get { return mouseDownEvent; }
650set { mouseDownEvent = value; }
651}
652
653/// <summary>
654/// Gets or sets a script event name that will be fired when the
655/// mouse enters the object's bounds in the preview window.
656/// </summary>
657[Category("Preview")]
658public string MouseEnterEvent
659{
660get { return mouseEnterEvent; }
661set { mouseEnterEvent = value; }
662}
663
664/// <summary>
665/// Gets or sets a script event name that will be fired when the
666/// mouse leaves the object's bounds in the preview window.
667/// </summary>
668[Category("Preview")]
669public string MouseLeaveEvent
670{
671get { return mouseLeaveEvent; }
672set { mouseLeaveEvent = value; }
673}
674#endregion
675
676#region Public Methods
677/// <inheritdoc/>
678public override void Assign(Base source)
679{
680base.Assign(source);
681
682ReportComponentBase src = source as ReportComponentBase;
683Exportable = src.Exportable;
684ExportableExpression = src.ExportableExpression;
685Border = src.Border.Clone();
686Fill = src.Fill.Clone();
687Bookmark = src.Bookmark;
688Hyperlink.Assign(src.Hyperlink);
689CanGrow = src.CanGrow;
690CanShrink = src.CanShrink;
691GrowToBottom = src.GrowToBottom;
692ShiftMode = src.ShiftMode;
693style = src.Style;
694EvenStyle = src.EvenStyle;
695HoverStyle = src.HoverStyle;
696EvenStylePriority = src.EvenStylePriority;
697PageBreak = src.PageBreak;
698PrintOn = src.PrintOn;
699BeforePrintEvent = src.BeforePrintEvent;
700AfterPrintEvent = src.AfterPrintEvent;
701AfterDataEvent = src.AfterDataEvent;
702ClickEvent = src.ClickEvent;
703Cursor = src.Cursor;
704MouseMoveEvent = src.MouseMoveEvent;
705MouseUpEvent = src.MouseUpEvent;
706MouseDownEvent = src.MouseDownEvent;
707MouseEnterEvent = src.MouseEnterEvent;
708MouseLeaveEvent = src.MouseLeaveEvent;
709}
710
711/// <summary>
712/// Applies the style settings.
713/// </summary>
714/// <param name="style">Style to apply.</param>
715public virtual void ApplyStyle(Style style)
716{
717if (style.ApplyBorder)
718Border = style.Border.Clone();
719if (style.ApplyFill)
720Fill = style.Fill.Clone();
721}
722
723internal void ApplyStyle(string style)
724{
725if (!String.IsNullOrEmpty(style) && Report != null)
726{
727StyleCollection styles = Report.Styles;
728int index = styles.IndexOf(style);
729if (index != -1)
730ApplyStyle(styles[index]);
731}
732}
733
734internal void ApplyEvenStyle()
735{
736if (!String.IsNullOrEmpty(EvenStyle) && Report != null)
737{
738StyleCollection styles = Report.Styles;
739int index = styles.IndexOf(EvenStyle);
740if (index != -1)
741{
742Style style = styles[index];
743if (EvenStylePriority == StylePriority.UseFill)
744Fill = style.Fill.Clone();
745else
746ApplyStyle(style);
747}
748}
749}
750
751/// <summary>
752/// Saves the current style.
753/// </summary>
754public virtual void SaveStyle()
755{
756savedBorder = Border;
757savedFill = Fill;
758}
759
760/// <summary>
761/// Restores the current style.
762/// </summary>
763public virtual void RestoreStyle()
764{
765Border = savedBorder;
766Fill = savedFill;
767}
768
769/// <summary>
770/// Draws the object's background.
771/// </summary>
772/// <param name="e">Draw event arguments.</param>
773public void DrawBackground(FRPaintEventArgs e)
774{
775if (Width < 0.01 || Height < 0.01)
776return;
777Fill.Draw(e, AbsBounds);
778}
779
780/// <inheritdoc/>
781public override void Draw(FRPaintEventArgs e)
782{
783DrawBackground(e);
784base.Draw(e);
785}
786
787/// <summary>
788/// Determines if the object is visible on current drawing surface.
789/// </summary>
790/// <param name="e">Draw event arguments.</param>
791public virtual bool IsVisible(FRPaintEventArgs e)
792{
793RectangleF objRect = new RectangleF(AbsLeft * e.ScaleX, AbsTop * e.ScaleY,
794Width * e.ScaleX + 1, Height * e.ScaleY + 1);
795return e.Graphics.IsVisible(objRect);
796}
797
798/// <summary>
799/// Validate this object.
800/// </summary>
801/// <returns>List of errors</returns>
802public virtual List<ValidationError> Validate()
803{
804List<ValidationError> listError = new List<ValidationError>();
805
806if (Height <= 0 || Width <= 0)
807listError.Add(new ValidationError(Name, ValidationError.ErrorLevel.Error, Res.Get("Messages,Validator,IncorrectSize"), this));
808
809if (Name == "")
810listError.Add(new ValidationError(Name, ValidationError.ErrorLevel.Error, Res.Get("Messages,Validator,UnnamedObject"), this));
811
812if (Parent is ReportComponentBase && !Validator.RectContainInOtherRect((Parent as ReportComponentBase).AbsBounds, this.AbsBounds))
813listError.Add(new ValidationError(Name, ValidationError.ErrorLevel.Error, Res.Get("Messages,Validator,OutOfBounds"), this));
814
815return listError;
816}
817
818/// <inheritdoc/>
819public override void Serialize(FRWriter writer)
820{
821ReportComponentBase c = writer.DiffObject as ReportComponentBase;
822base.Serialize(writer);
823
824if (Exportable != c.Exportable)
825writer.WriteBool("Exportable", Exportable);
826if (ExportableExpression != c.ExportableExpression)
827writer.WriteStr("ExportableExpression", ExportableExpression);
828Border.Serialize(writer, "Border", c.Border);
829//if(Fill != c.Fill)
830Fill.Serialize(writer, "Fill", c.Fill);
831if (Cursor != c.Cursor && !Config.WebMode)
832writer.WriteValue("Cursor", Cursor);
833Hyperlink.Serialize(writer, c.Hyperlink);
834if (Bookmark != c.Bookmark)
835writer.WriteStr("Bookmark", Bookmark);
836if (writer.SerializeTo != SerializeTo.Preview)
837{
838if (CanGrow != c.CanGrow)
839writer.WriteBool("CanGrow", CanGrow);
840if (CanShrink != c.CanShrink)
841writer.WriteBool("CanShrink", CanShrink);
842if (GrowToBottom != c.GrowToBottom)
843writer.WriteBool("GrowToBottom", GrowToBottom);
844if (ShiftMode != c.ShiftMode)
845writer.WriteValue("ShiftMode", ShiftMode);
846if (FlagSerializeStyle && Style != c.Style)
847writer.WriteStr("Style", Style);
848if (EvenStyle != c.EvenStyle)
849writer.WriteStr("EvenStyle", EvenStyle);
850if (EvenStylePriority != c.EvenStylePriority)
851writer.WriteValue("EvenStylePriority", EvenStylePriority);
852if (HoverStyle != c.HoverStyle)
853writer.WriteStr("HoverStyle", HoverStyle);
854if (PageBreak != c.PageBreak)
855writer.WriteBool("PageBreak", PageBreak);
856if (PrintOn != c.PrintOn)
857writer.WriteValue("PrintOn", PrintOn);
858if (BeforePrintEvent != c.BeforePrintEvent)
859writer.WriteStr("BeforePrintEvent", BeforePrintEvent);
860if (AfterPrintEvent != c.AfterPrintEvent)
861writer.WriteStr("AfterPrintEvent", AfterPrintEvent);
862if (AfterDataEvent != c.AfterDataEvent)
863writer.WriteStr("AfterDataEvent", AfterDataEvent);
864if (ClickEvent != c.ClickEvent)
865writer.WriteStr("ClickEvent", ClickEvent);
866if (MouseMoveEvent != c.MouseMoveEvent)
867writer.WriteStr("MouseMoveEvent", MouseMoveEvent);
868if (MouseUpEvent != c.MouseUpEvent)
869writer.WriteStr("MouseUpEvent", MouseUpEvent);
870if (MouseDownEvent != c.MouseDownEvent)
871writer.WriteStr("MouseDownEvent", MouseDownEvent);
872if (MouseEnterEvent != c.MouseEnterEvent)
873writer.WriteStr("MouseEnterEvent", MouseEnterEvent);
874if (MouseLeaveEvent != c.MouseLeaveEvent)
875writer.WriteStr("MouseLeaveEvent", MouseLeaveEvent);
876}
877}
878
879/// <summary>
880///
881/// </summary>
882/// <param name="reader"></param>
883public override void Deserialize(FRReader reader)
884{
885base.Deserialize(reader);
886Fill.Deserialize(reader, "Fill");
887}
888
889/// <summary>
890/// This method fires the <b>Click</b> event and the script code connected to the <b>ClickEvent</b>.
891/// </summary>
892/// <param name="e">Event data.</param>
893public virtual void OnClick(EventArgs e)
894{
895if (Click != null)
896Click(this, e);
897InvokeEvent(ClickEvent, e);
898}
899
900/// <inheritdoc/>
901public override void OnAfterLoad()
902{
903// if hyperlink is set to external report, we need to fix relative path to report
904Hyperlink.OnAfterLoad();
905}
906
907/// <summary>
908/// Checks if there are any listeners to the Click event.
909/// </summary>
910public bool HasClickListeners()
911{
912return Click != null;
913}
914#endregion
915
916#region Report Engine
917/// <summary>
918/// Resets the data from the previous report run.
919/// </summary>
920public virtual void ResetData()
921{
922}
923
924/// <summary>
925/// Initializes the object before running a report.
926/// </summary>
927/// <remarks>
928/// This method is used by the report engine, do not call it directly.
929/// </remarks>
930public virtual void InitializeComponent()
931{
932// update the component's style
933Style = Style;
934Fill.InitializeComponent();
935}
936
937/// <summary>
938/// Performs a finalization after the report is finished.
939/// </summary>
940/// <remarks>
941/// This method is used by the report engine, do not call it directly.
942/// </remarks>
943public virtual void FinalizeComponent()
944{
945Fill.FinalizeComponent();
946}
947
948/// <summary>
949/// Saves the object's state before printing it.
950/// </summary>
951/// <remarks>
952/// This method is called by the report engine before processing the object.
953/// <para/>Do not call it directly. You may override it if you are developing a new FastReport component.
954/// In this method you should save any object properties that may be changed during the object printing.
955/// The standard implementation saves the object's bounds, visibility, bookmark and hyperlink.
956/// </remarks>
957public virtual void SaveState()
958{
959savedBounds = Bounds;
960savedVisible = Visible;
961savedBookmark = Bookmark;
962savedBorder = Border;
963savedFill = Fill;
964Hyperlink.SaveState();
965}
966
967/// <summary>
968/// Restores the object's state after printing it.
969/// </summary>
970/// <remarks>
971/// This method is called by the report engine after processing the object.
972/// <para/>Do not call it directly. You may override it if you are developing a new FastReport component.
973/// In this method you should restore the object properties that were saved by the <see cref="SaveState"/> method.
974/// </remarks>
975public virtual void RestoreState()
976{
977Bounds = savedBounds;
978Visible = savedVisible;
979Bookmark = savedBookmark;
980Hyperlink.RestoreState();
981Border = savedBorder;
982Fill = savedFill;
983}
984
985/// <summary>
986/// Calculates the object's height.
987/// </summary>
988/// <returns>Actual object's height, in pixels.</returns>
989/// <remarks>
990/// Applicable to objects that contain several text lines, such as TextObject. Returns the height needed
991/// to display all the text lines.
992/// </remarks>
993public virtual float CalcHeight()
994{
995return Height;
996}
997
998/// <summary>
999/// Gets the data from a datasource that the object is connected to.
1000/// </summary>
1001/// <remarks>
1002/// This method is called by the report engine before processing the object.
1003/// <para/>Do not call it directly. You may override it if you are developing a new FastReport component.
1004/// In this method you should get the data from a datasource that the object is connected to.
1005/// </remarks>
1006public virtual void GetData()
1007{
1008Hyperlink.Calculate();
1009
1010if (!String.IsNullOrEmpty(Bookmark))
1011{
1012object value = Report.Calc(Bookmark);
1013Bookmark = value == null ? "" : value.ToString();
1014}
1015}
1016
1017/// <inheritdoc/>
1018public override string[] GetExpressions()
1019{
1020List<string> expressions = new List<string>();
1021
1022string[] baseExpressions = base.GetExpressions();
1023if (baseExpressions != null)
1024{
1025expressions.AddRange(baseExpressions);
1026}
1027
1028if (!String.IsNullOrEmpty(Hyperlink.Expression))
1029expressions.Add(Hyperlink.Expression);
1030if (!String.IsNullOrEmpty(Bookmark))
1031expressions.Add(Bookmark);
1032
1033if (!String.IsNullOrEmpty(ExportableExpression))
1034{
1035string expression = Code.CodeUtils.FixExpressionWithBrackets(ExportableExpression);
1036if (expression.ToLower() == "true" || expression.ToLower() == "false")
1037{
1038expression = expression.ToLower();
1039}
1040expressions.Add(expression);
1041}
1042
1043return expressions.ToArray();
1044}
1045
1046/// <summary>
1047/// This method fires the <b>BeforePrint</b> event and the script code connected to the <b>BeforePrintEvent</b>.
1048/// </summary>
1049/// <param name="e">Event data.</param>
1050public virtual void OnBeforePrint(EventArgs e)
1051{
1052if (BeforePrint != null)
1053BeforePrint(this, e);
1054InvokeEvent(BeforePrintEvent, e);
1055}
1056
1057/// <summary>
1058/// This method fires the <b>AfterPrint</b> event and the script code connected to the <b>AfterPrintEvent</b>.
1059/// </summary>
1060/// <param name="e">Event data.</param>
1061public virtual void OnAfterPrint(EventArgs e)
1062{
1063if (AfterPrint != null)
1064AfterPrint(this, e);
1065InvokeEvent(AfterPrintEvent, e);
1066}
1067
1068/// <summary>
1069/// This method fires the <b>AfterData</b> event and the script code connected to the <b>AfterDataEvent</b>.
1070/// </summary>
1071/// <param name="e">Event data.</param>
1072public virtual void OnAfterData(EventArgs e)
1073{
1074if (AfterData != null)
1075AfterData(this, e);
1076InvokeEvent(AfterDataEvent, e);
1077}
1078
1079internal void OnAfterData()
1080{
1081OnAfterData(EventArgs.Empty);
1082}
1083#endregion
1084
1085/// <summary>
1086/// Initializes a new instance of the <see cref="ReportComponentBase"/> class with default settings.
1087/// </summary>
1088public ReportComponentBase()
1089{
1090border = new Border();
1091fill = new SolidFill();
1092hyperlink = new Hyperlink(this);
1093bookmark = "";
1094exportable = true;
1095exportableExpression = "";
1096flagUseFill = true;
1097flagUseBorder = true;
1098flagPreviewVisible = true;
1099flagSerializeStyle = true;
1100shiftMode = ShiftMode.Always;
1101style = "";
1102evenStyle = "";
1103hoverStyle = "";
1104printOn = PrintOn.FirstPage | PrintOn.LastPage | PrintOn.OddPages | PrintOn.EvenPages | PrintOn.RepeatedBand | PrintOn.SinglePage;
1105beforePrintEvent = "";
1106afterPrintEvent = "";
1107afterDataEvent = "";
1108clickEvent = "";
1109cursor = Cursors.Default;
1110mouseMoveEvent = "";
1111mouseUpEvent = "";
1112mouseDownEvent = "";
1113mouseEnterEvent = "";
1114mouseLeaveEvent = "";
1115SetFlags(Flags.CanGroup, true);
1116if (BaseName.EndsWith("Object"))
1117BaseName = ClassName.Substring(0, ClassName.Length - 6);
1118}
1119}
1120}