123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using System.ComponentModel;
- using System.Drawing.Drawing2D;
- using FastReport.Utils;
- using FastReport.Design.PageDesigners.Page;
- namespace FastReport
- {
- partial class BandBase
- {
- #region Fields
- internal static int HeaderSize { get { return 20; } }
- #endregion
- #region Properties
- /// <inheritdoc/>
- [Browsable(false)]
- public override float Left
- {
- get { return base.Left; }
- set { base.Left = value; }
- }
- /// <inheritdoc/>
- [Browsable(false)]
- public override float Top
- {
- get { return base.Top; }
- set { base.Top = value; }
- }
- /// <inheritdoc/>
- [Browsable(false)]
- public override float Width
- {
- get { return base.Width; }
- set { base.Width = value; }
- }
- /// <summary>
- /// This property is not relevant to this class.
- /// </summary>
- [Browsable(false)]
- public override DockStyle Dock
- {
- get { return base.Dock; }
- set { base.Dock = value; }
- }
- /// <summary>
- /// This property is not relevant to this class.
- /// </summary>
- [Browsable(false)]
- public override AnchorStyles Anchor
- {
- get { return base.Anchor; }
- set { base.Anchor = value; }
- }
- /// <summary>
- /// This property is not relevant to this class.
- /// </summary>
- [Browsable(false)]
- public new bool GrowToBottom
- {
- get { return base.GrowToBottom; }
- set { base.GrowToBottom = value; }
- }
- /// <summary>
- /// This property is not relevant to this class.
- /// </summary>
- [Browsable(false)]
- public new ShiftMode ShiftMode
- {
- get { return base.ShiftMode; }
- set { base.ShiftMode = value; }
- }
- /// <inheritdoc/>
- [DefaultValue(false)]
- public new bool CanBreak
- {
- get { return base.CanBreak; }
- set { base.CanBreak = value; }
- }
- /// <summary>
- /// This property is not relevant to this class.
- /// </summary>
- [Browsable(false)]
- public new BreakableComponent BreakTo
- {
- get { return base.BreakTo; }
- set { base.BreakTo = value; }
- }
- internal bool CanDelete
- {
- get
- {
- if (Page != null)
- {
- // do not delete the sole band on the page
- ObjectCollection pageObjects = Page.AllObjects;
- ObjectCollection bands = new ObjectCollection();
- foreach (Base obj in pageObjects)
- {
- // fix: it was possible to delete the band if it has a child band
- if (obj is BandBase && (obj == this || !(obj is ChildBand)))
- bands.Add(obj);
- }
- return bands.Count > 1;
- }
- else
- return false;
- }
- }
- internal float DesignWidth
- {
- get
- {
- ReportPage page = Page as ReportPage;
- if (page != null && page.ExtraDesignWidth)
- {
- if (page.Columns.Count <= 1 || !IsColumnDependentBand)
- return Width * 5;
- }
- return Width;
- }
- }
- #endregion
- #region Public Methods
- /// <inheritdoc/>
- public override void DrawSelection(FRPaintEventArgs e)
- {
- DrawSelectionPoint(e, Pens.Black, Brushes.White, Left + Width / 2, Top + Height + 2);
- DrawSelectionPoint(e, Pens.Black, Brushes.White, Left + Width / 2, Top + 2);
- }
- /// <inheritdoc/>
- public override bool PointInObject(PointF point)
- {
- if (IsDesigning)
- {
- if (ReportWorkspace.ClassicView)
- return new RectangleF(Left, Top - (HeaderSize - 1), DesignWidth, Height + HeaderSize - 1).Contains(point);
- else
- return new RectangleF(Left, Top, DesignWidth, Height).Contains(point);
- }
- return AbsBounds.Contains(point);
- }
- /// <inheritdoc/>
- public override void HandleMouseDown(FRMouseEventArgs e)
- {
- base.HandleMouseDown(e);
- if (e.handled)
- {
- if (e.modifierKeys != Keys.Shift)
- {
- e.mode = WorkspaceMode2.SelectionRect;
- e.activeObject = this;
- }
- }
- }
- /// <inheritdoc/>
- public override void HandleMouseHover(FRMouseEventArgs e)
- {
- base.HandleMouseHover(e);
- if (e.handled)
- e.cursor = Cursors.Default;
- }
- /// <inheritdoc/>
- public override void HandleMouseMove(FRMouseEventArgs e)
- {
- PointF point = new PointF(e.x, e.y);
- if (e.button == MouseButtons.None)
- {
- e.sizingPoint = SizingPoint.None;
- if (point.Y > Bounds.Bottom && point.Y < Bounds.Bottom + 4)
- {
- e.mode = WorkspaceMode2.Size;
- e.sizingPoint = SizingPoint.BottomCenter;
- e.cursor = Cursors.HSplit;
- e.handled = true;
- }
- if (point.Y > Bounds.Top && point.Y < Bounds.Top + 4 && point.X > (Bounds.Left + Bounds.Right) / 2 - 2 && point.X < (Bounds.Left + Bounds.Right) / 2 + 2)
- {
- e.mode = WorkspaceMode2.Size;
- e.sizingPoint = SizingPoint.TopCenter;
- e.cursor = Cursors.HSplit;
- e.handled = true;
- }
- }
- else
- {
- if (e.activeObject == this && e.mode == WorkspaceMode2.Size)
- {
- if (e.sizingPoint == SizingPoint.BottomCenter)
- {
- Height += e.delta.Y;
- FixHeight();
- }
- if (e.sizingPoint == SizingPoint.TopCenter)
- {
- Height -= e.delta.Y;
- FixHeightWithComponentsShift(e.delta.Y);
- }
- e.handled = true;
- }
- }
- }
- /// <inheritdoc/>
- public override void HandleMouseUp(FRMouseEventArgs e)
- {
- if (Report == null)
- return;
- if (e.mode == WorkspaceMode2.SelectionRect)
- {
- ObjectCollection selectedList = new ObjectCollection();
- // find objects inside the selection rect
- for (int i = 0; i < Report.Designer.Objects.Count; i++)
- {
- Base c = Report.Designer.Objects[i];
- if (c is ComponentBase && !(c is BandBase))
- {
- e.handled = false;
- (c as ComponentBase).HandleMouseUp(e);
- // object is inside
- if (e.handled)
- selectedList.Add(c);
- }
- }
- if (selectedList.Count > 0)
- selectedList.CopyTo(Report.Designer.SelectedObjects);
- }
- FixHeight();
- }
- /// <inheritdoc/>
- public override SizeF GetPreferredSize()
- {
- SizeF result = new SizeF(0, 0);
- switch (ReportWorkspace.Grid.GridUnits)
- {
- case PageUnits.Millimeters:
- result = new SizeF(Units.Millimeters * 10, Units.Millimeters * 10);
- break;
- case PageUnits.Centimeters:
- result = new SizeF(Units.Centimeters * 1, Units.Centimeters * 1);
- break;
- case PageUnits.Inches:
- result = new SizeF(Units.Inches * 0.5f, Units.Inches * 0.5f);
- break;
- case PageUnits.HundrethsOfInch:
- result = new SizeF(Units.HundrethsOfInch * 50, Units.HundrethsOfInch * 50);
- break;
- }
- return result;
- }
- /// <inheritdoc/>
- public override void Delete()
- {
- if (CanDelete)
- Dispose();
- }
- internal virtual string GetInfoText()
- {
- return "";
- }
- internal void DrawBandHeader(Graphics g, RectangleF rect, bool drawTopLine)
- {
- if (Report == null)
- return;
- Color color1 = Color.Empty;
- if (this is GroupHeaderBand || this is GroupFooterBand)
- color1 = Color.FromArgb(144, 228, 0);
- else if (this is DataBand)
- color1 = Color.FromArgb(255, 144, 0);
- else
- color1 = UIStyleUtils.GetGrayColor(Report.Designer.UIStyle);
- Color color2 = Color.FromArgb(100, color1);
- Color color3 = Color.FromArgb(180, Color.White);
- Color color4 = Color.Transparent;
- g.FillRectangle(Brushes.White, rect);
- using (LinearGradientBrush b = new LinearGradientBrush(rect, color1, color2, 90))
- {
- g.FillRectangle(b, rect);
- }
- rect.Height /= 3;
- using (LinearGradientBrush b = new LinearGradientBrush(rect, color3, color4, 90))
- {
- g.FillRectangle(b, rect);
- }
- if (drawTopLine)
- {
- using (Pen p = new Pen(color1))
- {
- g.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Top);
- }
- }
- }
- /// <inheritdoc/>
- public override ContextMenuBase GetContextMenu()
- {
- return new BandBaseMenu(Report.Designer);
- }
- /// <inheritdoc/>
- public override void Draw(FRPaintEventArgs e)
- {
- if (Report == null)
- return;
- UpdateWidth();
- if (IsDesigning)
- {
- IGraphics g = e.Graphics;
- RectangleF bounds = Bounds;
- bounds.X *= e.ScaleX;
- bounds.Y *= e.ScaleY;
- bounds.Width = DesignWidth * e.ScaleX;
- bounds.Height *= e.ScaleY;
- if (ReportWorkspace.ClassicView && Width != 0)
- {
- RectangleF fillRect = new RectangleF(bounds.Left, bounds.Top - (BandBase.HeaderSize - 1) * e.ScaleY,
- bounds.Width, (BandBase.HeaderSize - 1) * e.ScaleY);
- if (bounds.Top == BandBase.HeaderSize)
- {
- fillRect.Y = 0;
- fillRect.Height += e.ScaleY;
- }
- DrawBandHeader(g.Graphics, fillRect, true);
- ObjectInfo info = RegisteredObjects.FindObject(this);
- string text = Res.Get(info.Text);
- if (GetInfoText() != "")
- text += ": " + GetInfoText();
- fillRect.X += 4;
- using (Font f = new Font(DrawUtils.DefaultFont.Name, DrawUtils.DefaultFont.Size * 96 / DrawUtils.ScreenDpi * Report.Designer.ZoomDpi))
- TextRenderer.DrawText(g.Graphics, text, f,
- Rectangle.Round(fillRect), SystemColors.WindowText, TextFormatFlags.VerticalCenter | TextFormatFlags.PreserveGraphicsTranslateTransform);
- }
- g.FillRectangle(SystemBrushes.Window, bounds.Left, (int)Math.Round(bounds.Top),
- bounds.Width, bounds.Height + (ReportWorkspace.ClassicView ? 1 : 4));
- DrawBackground(e);
- if (ReportWorkspace.ShowGrid)
- ReportWorkspace.Grid.Draw(g.Graphics, bounds, e.ScaleX);
- if (!ReportWorkspace.ClassicView)
- {
- Pen pen = e.Cache.GetPen(Color.Silver, 1, DashStyle.Dot);
- g.DrawLine(pen, bounds.Left, bounds.Bottom + 1, bounds.Right + 1, bounds.Bottom + 1);
- g.DrawLine(pen, bounds.Left + 1, bounds.Bottom + 2, bounds.Right + 1, bounds.Bottom + 2);
- g.DrawLine(pen, bounds.Left, bounds.Bottom + 3, bounds.Right + 1, bounds.Bottom + 3);
- }
- }
- else
- {
- DrawBackground(e);
- Border.Draw(e, new RectangleF(AbsLeft, AbsTop, Width, Height));
- }
- }
- internal void FixHeight()
- {
- float maxHeight = Height;
- foreach (ReportComponentBase c in Objects)
- {
- if (c.Bottom > maxHeight)
- maxHeight = c.Bottom;
- }
- if (maxHeight < 0)
- maxHeight = 0;
- Height = maxHeight;
- }
- internal void FixHeightWithComponentsShift(float deltaY)
- {
- float minTop = Height;
- float maxBottom = 0;
- float minHeight = Height;
- // Calculate minimum top of all components on this band.
- foreach (ReportComponentBase component in Objects)
- {
- if (component.Top < minTop)
- {
- minTop = component.Top;
- }
- }
- // Calculate maximum bottom of all components on this band.
- foreach (ReportComponentBase component in Objects)
- {
- if (component.Bottom > maxBottom)
- {
- maxBottom = component.Bottom;
- }
- }
- // Calculate minimum height of band with components shift.
- minHeight = maxBottom - minTop;
- // Minimum height with compenents shift can't be negative.
- if (minHeight < 0)
- {
- minHeight = 0;
- }
- // Prevent incorrect movement of objects when mouse moves too fast.
- if (minTop < deltaY)
- {
- deltaY = minTop;
- }
- // Size of band should be decreased.
- if (deltaY > 0)
- {
- // There is enough place to move components up.
- if (minTop > 0)
- {
- // Move all components up.
- foreach (ReportComponentBase component in Objects)
- {
- component.Top -= deltaY;
- }
- }
- }
- else
- {
- // Move all components down.
- foreach (ReportComponentBase component in Objects)
- {
- component.Top -= deltaY;
- }
- }
- // Height can't be less then minHeight.
- if (Height < minHeight)
- {
- Height = minHeight;
- }
- }
- #endregion
- }
- }
|