FastReport

Форк
0
/
ReportComponentBase.cs 
1120 строк · 38.2 Кб
1
using System;
2
using System.Collections.Generic;
3
using System.Drawing;
4
using System.ComponentModel;
5
using FastReport.Utils;
6
using System.Windows.Forms;
7
using System.Drawing.Design;
8

9
namespace FastReport
10
{
11
    /// <summary>
12
    /// The automatic shift mode.
13
    /// </summary>
14
    public enum ShiftMode
15
    {
16
        /// <summary>
17
        /// Do not shift the object.
18
        /// </summary>
19
        Never,
20

21
        /// <summary>
22
        /// Shift the object up or down if any object above it shrinks or grows.
23
        /// </summary>
24
        Always,
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>
30
        WhenOverlapped
31
    }
32

33
    /// <summary>
34
    /// Specifies where to print an object.
35
    /// </summary>
36
    [Flags]
37
    [TypeConverter(typeof(FastReport.TypeConverters.FlagConverter))]
38
    public enum PrintOn
39
    {
40
        /// <summary>
41
        /// Do not print the object.
42
        /// </summary>
43
        None = 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>
49
        FirstPage = 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>
56
        LastPage = 2,
57

58
        /// <summary>
59
        /// Print the object on odd pages only.
60
        /// </summary>
61
        OddPages = 4,
62

63
        /// <summary>
64
        /// Print the object on even pages only.
65
        /// </summary>
66
        EvenPages = 8,
67

68
        /// <summary>
69
        /// Print the object on band with "Repeat on Every Page" flag when that band is repeated. 
70
        /// </summary>
71
        RepeatedBand = 16,
72

73
        /// <summary>
74
        /// Print the object if the report has single page only.
75
        /// </summary>
76
        SinglePage = 32
77
    }
78

79

80
    /// <summary>
81
    /// Specifies the style properties to use when style is applied.
82
    /// </summary>
83
    public enum StylePriority
84
    {
85
        /// <summary>
86
        /// Use the fill property of the style.
87
        /// </summary>
88
        UseFill,
89

90
        /// <summary>
91
        /// Use all style properties.
92
        /// </summary>
93
        UseAll
94
    }
95

96
    /// <summary>
97
    /// Base class for all report objects.
98
    /// </summary>
99
    public abstract partial class ReportComponentBase : ComponentBase
100
    {
101
        #region Fields
102
        private bool exportable;
103
        private string exportableExpression;
104
        private Border border;
105
        private FillBase fill;
106
        private string bookmark;
107
        private Hyperlink hyperlink;
108
        private bool canGrow;
109
        private bool canShrink;
110
        private bool growToBottom;
111
        private ShiftMode shiftMode;
112
        private string style;
113
        private string evenStyle;
114
        private string hoverStyle;
115
        private StylePriority evenStylePriority;
116
        private bool pageBreak;
117
        private PrintOn printOn;
118
        private string beforePrintEvent;
119
        private string afterPrintEvent;
120
        private string afterDataEvent;
121
        private string clickEvent;
122
        private bool flagSimpleBorder;
123
        private bool flagUseBorder;
124
        private bool flagUseFill;
125
        private bool flagPreviewVisible;
126
        private bool flagSerializeStyle;
127
        private bool flagProvidesHyperlinkValue;
128
        private RectangleF savedBounds;
129
        private bool savedVisible;
130
        private string savedBookmark;
131
        private Border savedBorder;
132
        private FillBase savedFill;
133
        private Cursor cursor;
134
        private string mouseMoveEvent;
135
        private string mouseUpEvent;
136
        private string mouseDownEvent;
137
        private string mouseEnterEvent;
138
        private 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>
145
        public event EventHandler BeforePrint;
146

147
        /// <summary>
148
        /// This event occurs after the object was added to the preview pages.
149
        /// </summary>
150
        public event EventHandler AfterPrint;
151

152
        /// <summary>
153
        /// This event occurs after the object was filled with data.
154
        /// </summary>
155
        public event EventHandler AfterData;
156

157
        /// <summary>
158
        /// This event occurs when the user clicks the object in the preview window.
159
        /// </summary>
160
        public 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")]
167
        public bool Exportable
168
        {
169
            get { return exportable; }
170
            set { 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))]
179
        public virtual string ExportableExpression
180
        {
181
            get { return exportableExpression; }
182
            set { exportableExpression = value; }
183
        }
184

185
        /// <summary>
186
        /// Gets or sets an object's border.
187
        /// </summary>
188
        [Category("Appearance")]
189
        public virtual Border Border
190
        {
191
            get { return border; }
192
            set
193
            {
194
                border = value;
195
                if (!String.IsNullOrEmpty(Style))
196
                    Style = "";
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))]
216
        public virtual FillBase Fill
217
        {
218
            get
219
            {
220
                return fill;
221
            }
222
            set
223
            {
224
                if (value == null)
225
                    throw new ArgumentNullException("Fill");
226
                fill = value;
227
                if (!String.IsNullOrEmpty(Style))
228
                    Style = "";
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)]
240
        public Color FillColor
241
        {
242
            get { return Fill is SolidFill ? (Fill as SolidFill).Color : Color.Transparent; }
243
            set { 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))]
256
        public string Bookmark
257
        {
258
            get { return bookmark; }
259
            set { 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))]
279
        public Hyperlink Hyperlink
280
        {
281
            get { return hyperlink; }
282
            set { 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")]
294
        public bool CanGrow
295
        {
296
            get { return canGrow; }
297
            set { 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")]
309
        public bool CanShrink
310
        {
311
            get { return canShrink; }
312
            set { 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")]
324
        public bool GrowToBottom
325
        {
326
            get { return growToBottom; }
327
            set { 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")]
338
        public ShiftMode ShiftMode
339
        {
340
            get { return shiftMode; }
341
            set { 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))]
354
        public string Style
355
        {
356
            get { return style; }
357
            set
358
            {
359
                ApplyStyle(value);
360
                style = 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))]
372
        public string EvenStyle
373
        {
374
            get { return evenStyle; }
375
            set { 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))]
387
        public string HoverStyle
388
        {
389
            get { return hoverStyle; }
390
            set { 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")]
402
        public StylePriority EvenStylePriority
403
        {
404
            get { return evenStylePriority; }
405
            set { 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")]
414
        public bool PageBreak
415
        {
416
            get { return pageBreak; }
417
            set { 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))]
430
        public PrintOn PrintOn
431
        {
432
            get { return printOn; }
433
            set { 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")]
440
        public string BeforePrintEvent
441
        {
442
            get { return beforePrintEvent; }
443
            set { 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")]
450
        public string AfterPrintEvent
451
        {
452
            get { return afterPrintEvent; }
453
            set { 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")]
460
        public string AfterDataEvent
461
        {
462
            get { return afterDataEvent; }
463
            set { 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")]
470
        public string ClickEvent
471
        {
472
            get { return clickEvent; }
473
            set { 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)]
485
        public bool FlagSimpleBorder
486
        {
487
            get { return flagSimpleBorder; }
488
            set { 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)]
498
        public bool FlagUseBorder
499
        {
500
            get { return flagUseBorder; }
501
            set { 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)]
511
        public bool FlagUseFill
512
        {
513
            get { return flagUseFill; }
514
            set { 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)]
521
        public bool FlagPreviewVisible
522
        {
523
            get { return flagPreviewVisible; }
524
            set { 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)]
535
        public bool FlagSerializeStyle
536
        {
537
            get { return flagSerializeStyle; }
538
            set { 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)]
549
        public bool FlagProvidesHyperlinkValue
550
        {
551
            get { return flagProvidesHyperlinkValue; }
552
            set { flagProvidesHyperlinkValue = value; }
553
        }
554

555
        /// <summary>
556
        /// Gets an object's parent band.
557
        /// </summary>
558
        internal BandBase Band
559
        {
560
            get
561
            {
562
                if (this is BandBase)
563
                    return this as BandBase;
564

565
                Base c = Parent;
566
                while (c != null)
567
                {
568
                    if (c is BandBase)
569
                        return c as BandBase;
570
                    c = c.Parent;
571
                }
572
                return null;
573
            }
574
        }
575

576
        /// <summary>
577
        /// Gets an object's parent data band.
578
        /// </summary>
579
        internal DataBand DataBand
580
        {
581
            get
582
            {
583
                if (this is DataBand)
584
                    return this as DataBand;
585

586
                Base c = Parent;
587
                while (c != null)
588
                {
589
                    if (c is DataBand)
590
                        return c as DataBand;
591
                    c = c.Parent;
592
                }
593

594
                ObjectCollection pageBands = Page.AllObjects;
595
                foreach (Base c1 in pageBands)
596
                {
597
                    if (c1 is DataBand)
598
                        return c1 as DataBand;
599
                }
600
                return null;
601
            }
602
        }
603

604
        [Browsable(false)]
605
        protected 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")]
614
        public Cursor Cursor
615
        {
616
            get { return cursor; }
617
            set { 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")]
625
        public string MouseMoveEvent
626
        {
627
            get { return mouseMoveEvent; }
628
            set { 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")]
636
        public string MouseUpEvent
637
        {
638
            get { return mouseUpEvent; }
639
            set { 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")]
647
        public string MouseDownEvent
648
        {
649
            get { return mouseDownEvent; }
650
            set { 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")]
658
        public string MouseEnterEvent
659
        {
660
            get { return mouseEnterEvent; }
661
            set { 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")]
669
        public string MouseLeaveEvent
670
        {
671
            get { return mouseLeaveEvent; }
672
            set { mouseLeaveEvent = value; }
673
        }
674
        #endregion
675

676
        #region Public Methods
677
        /// <inheritdoc/>
678
        public override void Assign(Base source)
679
        {
680
            base.Assign(source);
681

682
            ReportComponentBase src = source as ReportComponentBase;
683
            Exportable = src.Exportable;
684
            ExportableExpression = src.ExportableExpression;
685
            Border = src.Border.Clone();
686
            Fill = src.Fill.Clone();
687
            Bookmark = src.Bookmark;
688
            Hyperlink.Assign(src.Hyperlink);
689
            CanGrow = src.CanGrow;
690
            CanShrink = src.CanShrink;
691
            GrowToBottom = src.GrowToBottom;
692
            ShiftMode = src.ShiftMode;
693
            style = src.Style;
694
            EvenStyle = src.EvenStyle;
695
            HoverStyle = src.HoverStyle;
696
            EvenStylePriority = src.EvenStylePriority;
697
            PageBreak = src.PageBreak;
698
            PrintOn = src.PrintOn;
699
            BeforePrintEvent = src.BeforePrintEvent;
700
            AfterPrintEvent = src.AfterPrintEvent;
701
            AfterDataEvent = src.AfterDataEvent;
702
            ClickEvent = src.ClickEvent;
703
            Cursor = src.Cursor;
704
            MouseMoveEvent = src.MouseMoveEvent;
705
            MouseUpEvent = src.MouseUpEvent;
706
            MouseDownEvent = src.MouseDownEvent;
707
            MouseEnterEvent = src.MouseEnterEvent;
708
            MouseLeaveEvent = src.MouseLeaveEvent;
709
        }
710

711
        /// <summary>
712
        /// Applies the style settings.
713
        /// </summary>
714
        /// <param name="style">Style to apply.</param>
715
        public virtual void ApplyStyle(Style style)
716
        {
717
            if (style.ApplyBorder)
718
                Border = style.Border.Clone();
719
            if (style.ApplyFill)
720
                Fill = style.Fill.Clone();
721
        }
722

723
        internal void ApplyStyle(string style)
724
        {
725
            if (!String.IsNullOrEmpty(style) && Report != null)
726
            {
727
                StyleCollection styles = Report.Styles;
728
                int index = styles.IndexOf(style);
729
                if (index != -1)
730
                    ApplyStyle(styles[index]);
731
            }
732
        }
733

734
        internal void ApplyEvenStyle()
735
        {
736
            if (!String.IsNullOrEmpty(EvenStyle) && Report != null)
737
            {
738
                StyleCollection styles = Report.Styles;
739
                int index = styles.IndexOf(EvenStyle);
740
                if (index != -1)
741
                {
742
                    Style style = styles[index];
743
                    if (EvenStylePriority == StylePriority.UseFill)
744
                        Fill = style.Fill.Clone();
745
                    else
746
                        ApplyStyle(style);
747
                }
748
            }
749
        }
750

751
        /// <summary>
752
        /// Saves the current style.
753
        /// </summary>
754
        public virtual void SaveStyle()
755
        {
756
            savedBorder = Border;
757
            savedFill = Fill;
758
        }
759

760
        /// <summary>
761
        /// Restores the current style.
762
        /// </summary>
763
        public virtual void RestoreStyle()
764
        {
765
            Border = savedBorder;
766
            Fill = savedFill;
767
        }
768

769
        /// <summary>
770
        /// Draws the object's background.
771
        /// </summary>
772
        /// <param name="e">Draw event arguments.</param>
773
        public void DrawBackground(FRPaintEventArgs e)
774
        {
775
            if (Width < 0.01 || Height < 0.01)
776
                return;
777
            Fill.Draw(e, AbsBounds);
778
        }
779

780
        /// <inheritdoc/>
781
        public override void Draw(FRPaintEventArgs e)
782
        {
783
            DrawBackground(e);
784
            base.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>
791
        public virtual bool IsVisible(FRPaintEventArgs e)
792
        {
793
            RectangleF objRect = new RectangleF(AbsLeft * e.ScaleX, AbsTop * e.ScaleY,
794
              Width * e.ScaleX + 1, Height * e.ScaleY + 1);
795
            return e.Graphics.IsVisible(objRect);
796
        }
797

798
        /// <summary>
799
        /// Validate this object.
800
        /// </summary>
801
        /// <returns>List of errors</returns>
802
        public virtual List<ValidationError> Validate()
803
        {
804
            List<ValidationError> listError = new List<ValidationError>();
805

806
            if (Height <= 0 || Width <= 0)
807
                listError.Add(new ValidationError(Name, ValidationError.ErrorLevel.Error, Res.Get("Messages,Validator,IncorrectSize"), this));
808

809
            if (Name == "")
810
                listError.Add(new ValidationError(Name, ValidationError.ErrorLevel.Error, Res.Get("Messages,Validator,UnnamedObject"), this));
811

812
            if (Parent is ReportComponentBase && !Validator.RectContainInOtherRect((Parent as ReportComponentBase).AbsBounds, this.AbsBounds))
813
                listError.Add(new ValidationError(Name, ValidationError.ErrorLevel.Error, Res.Get("Messages,Validator,OutOfBounds"), this));
814

815
            return listError;
816
        }
817

818
        /// <inheritdoc/>
819
        public override void Serialize(FRWriter writer)
820
        {
821
            ReportComponentBase c = writer.DiffObject as ReportComponentBase;
822
            base.Serialize(writer);
823

824
            if (Exportable != c.Exportable)
825
                writer.WriteBool("Exportable", Exportable);
826
            if (ExportableExpression != c.ExportableExpression)
827
                writer.WriteStr("ExportableExpression", ExportableExpression);
828
            Border.Serialize(writer, "Border", c.Border);
829
            //if(Fill != c.Fill)
830
            Fill.Serialize(writer, "Fill", c.Fill);
831
            if (Cursor != c.Cursor && !Config.WebMode)
832
                writer.WriteValue("Cursor", Cursor);
833
            Hyperlink.Serialize(writer, c.Hyperlink);
834
            if (Bookmark != c.Bookmark)
835
                writer.WriteStr("Bookmark", Bookmark);
836
            if (writer.SerializeTo != SerializeTo.Preview)
837
            {
838
                if (CanGrow != c.CanGrow)
839
                    writer.WriteBool("CanGrow", CanGrow);
840
                if (CanShrink != c.CanShrink)
841
                    writer.WriteBool("CanShrink", CanShrink);
842
                if (GrowToBottom != c.GrowToBottom)
843
                    writer.WriteBool("GrowToBottom", GrowToBottom);
844
                if (ShiftMode != c.ShiftMode)
845
                    writer.WriteValue("ShiftMode", ShiftMode);
846
                if (FlagSerializeStyle && Style != c.Style)
847
                    writer.WriteStr("Style", Style);
848
                if (EvenStyle != c.EvenStyle)
849
                    writer.WriteStr("EvenStyle", EvenStyle);
850
                if (EvenStylePriority != c.EvenStylePriority)
851
                    writer.WriteValue("EvenStylePriority", EvenStylePriority);
852
                if (HoverStyle != c.HoverStyle)
853
                    writer.WriteStr("HoverStyle", HoverStyle);
854
                if (PageBreak != c.PageBreak)
855
                    writer.WriteBool("PageBreak", PageBreak);
856
                if (PrintOn != c.PrintOn)
857
                    writer.WriteValue("PrintOn", PrintOn);
858
                if (BeforePrintEvent != c.BeforePrintEvent)
859
                    writer.WriteStr("BeforePrintEvent", BeforePrintEvent);
860
                if (AfterPrintEvent != c.AfterPrintEvent)
861
                    writer.WriteStr("AfterPrintEvent", AfterPrintEvent);
862
                if (AfterDataEvent != c.AfterDataEvent)
863
                    writer.WriteStr("AfterDataEvent", AfterDataEvent);
864
                if (ClickEvent != c.ClickEvent)
865
                    writer.WriteStr("ClickEvent", ClickEvent);
866
                if (MouseMoveEvent != c.MouseMoveEvent)
867
                    writer.WriteStr("MouseMoveEvent", MouseMoveEvent);
868
                if (MouseUpEvent != c.MouseUpEvent)
869
                    writer.WriteStr("MouseUpEvent", MouseUpEvent);
870
                if (MouseDownEvent != c.MouseDownEvent)
871
                    writer.WriteStr("MouseDownEvent", MouseDownEvent);
872
                if (MouseEnterEvent != c.MouseEnterEvent)
873
                    writer.WriteStr("MouseEnterEvent", MouseEnterEvent);
874
                if (MouseLeaveEvent != c.MouseLeaveEvent)
875
                    writer.WriteStr("MouseLeaveEvent", MouseLeaveEvent);
876
            }
877
        }
878

879
        /// <summary>
880
        /// 
881
        /// </summary>
882
        /// <param name="reader"></param>
883
        public override void Deserialize(FRReader reader)
884
        {
885
            base.Deserialize(reader);
886
            Fill.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>
893
        public virtual void OnClick(EventArgs e)
894
        {
895
            if (Click != null)
896
                Click(this, e);
897
            InvokeEvent(ClickEvent, e);
898
        }
899

900
        /// <inheritdoc/>
901
        public override void OnAfterLoad()
902
        {
903
            // if hyperlink is set to external report, we need to fix relative path to report
904
            Hyperlink.OnAfterLoad();
905
        }
906

907
        /// <summary>
908
        /// Checks if there are any listeners to the Click event.
909
        /// </summary>
910
        public bool HasClickListeners()
911
        {
912
            return Click != null;
913
        }
914
        #endregion
915

916
        #region Report Engine
917
        /// <summary>
918
        /// Resets the data from the previous report run.
919
        /// </summary>
920
        public 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>
930
        public virtual void InitializeComponent()
931
        {
932
            // update the component's style
933
            Style = Style;
934
            Fill.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>
943
        public virtual void FinalizeComponent()
944
        {
945
            Fill.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>
957
        public virtual void SaveState()
958
        {
959
            savedBounds = Bounds;
960
            savedVisible = Visible;
961
            savedBookmark = Bookmark;
962
            savedBorder = Border;
963
            savedFill = Fill;
964
            Hyperlink.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>
975
        public virtual void RestoreState()
976
        {
977
            Bounds = savedBounds;
978
            Visible = savedVisible;
979
            Bookmark = savedBookmark;
980
            Hyperlink.RestoreState();
981
            Border = savedBorder;
982
            Fill = 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>
993
        public virtual float CalcHeight()
994
        {
995
            return 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>
1006
        public virtual void GetData()
1007
        {
1008
            Hyperlink.Calculate();
1009

1010
            if (!String.IsNullOrEmpty(Bookmark))
1011
            {
1012
                object value = Report.Calc(Bookmark);
1013
                Bookmark = value == null ? "" : value.ToString();
1014
            }
1015
        }
1016

1017
        /// <inheritdoc/>
1018
        public override string[] GetExpressions()
1019
        {
1020
            List<string> expressions = new List<string>();
1021

1022
            string[] baseExpressions = base.GetExpressions();
1023
            if (baseExpressions != null)
1024
            {
1025
                expressions.AddRange(baseExpressions);
1026
            }
1027

1028
            if (!String.IsNullOrEmpty(Hyperlink.Expression))
1029
                expressions.Add(Hyperlink.Expression);
1030
            if (!String.IsNullOrEmpty(Bookmark))
1031
                expressions.Add(Bookmark);
1032

1033
            if (!String.IsNullOrEmpty(ExportableExpression))
1034
            {
1035
                string expression = Code.CodeUtils.FixExpressionWithBrackets(ExportableExpression);
1036
                if (expression.ToLower() == "true" || expression.ToLower() == "false")
1037
                {
1038
                    expression = expression.ToLower();
1039
                }
1040
                expressions.Add(expression);
1041
            }
1042

1043
            return 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>
1050
        public virtual void OnBeforePrint(EventArgs e)
1051
        {
1052
            if (BeforePrint != null)
1053
                BeforePrint(this, e);
1054
            InvokeEvent(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>
1061
        public virtual void OnAfterPrint(EventArgs e)
1062
        {
1063
            if (AfterPrint != null)
1064
                AfterPrint(this, e);
1065
            InvokeEvent(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>
1072
        public virtual void OnAfterData(EventArgs e)
1073
        {
1074
            if (AfterData != null)
1075
                AfterData(this, e);
1076
            InvokeEvent(AfterDataEvent, e);
1077
        }
1078

1079
        internal void OnAfterData()
1080
        {
1081
            OnAfterData(EventArgs.Empty);
1082
        }
1083
        #endregion
1084

1085
        /// <summary>
1086
        /// Initializes a new instance of the <see cref="ReportComponentBase"/> class with default settings.
1087
        /// </summary>
1088
        public ReportComponentBase()
1089
        {
1090
            border = new Border();
1091
            fill = new SolidFill();
1092
            hyperlink = new Hyperlink(this);
1093
            bookmark = "";
1094
            exportable = true;
1095
            exportableExpression = "";
1096
            flagUseFill = true;
1097
            flagUseBorder = true;
1098
            flagPreviewVisible = true;
1099
            flagSerializeStyle = true;
1100
            shiftMode = ShiftMode.Always;
1101
            style = "";
1102
            evenStyle = "";
1103
            hoverStyle = "";
1104
            printOn = PrintOn.FirstPage | PrintOn.LastPage | PrintOn.OddPages | PrintOn.EvenPages | PrintOn.RepeatedBand | PrintOn.SinglePage;
1105
            beforePrintEvent = "";
1106
            afterPrintEvent = "";
1107
            afterDataEvent = "";
1108
            clickEvent = "";
1109
            cursor = Cursors.Default;
1110
            mouseMoveEvent = "";
1111
            mouseUpEvent = "";
1112
            mouseDownEvent = "";
1113
            mouseEnterEvent = "";
1114
            mouseLeaveEvent = "";
1115
            SetFlags(Flags.CanGroup, true);
1116
            if (BaseName.EndsWith("Object"))
1117
                BaseName = ClassName.Substring(0, ClassName.Length - 6);
1118
        }
1119
    }
1120
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.