BandBase.DesignExt.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using System.ComponentModel;
  5. using System.Drawing.Drawing2D;
  6. using FastReport.Utils;
  7. using FastReport.Design.PageDesigners.Page;
  8. namespace FastReport
  9. {
  10. partial class BandBase
  11. {
  12. #region Fields
  13. internal static int HeaderSize { get { return 20; } }
  14. #endregion
  15. #region Properties
  16. /// <inheritdoc/>
  17. [Browsable(false)]
  18. public override float Left
  19. {
  20. get { return base.Left; }
  21. set { base.Left = value; }
  22. }
  23. /// <inheritdoc/>
  24. [Browsable(false)]
  25. public override float Top
  26. {
  27. get { return base.Top; }
  28. set { base.Top = value; }
  29. }
  30. /// <inheritdoc/>
  31. [Browsable(false)]
  32. public override float Width
  33. {
  34. get { return base.Width; }
  35. set { base.Width = value; }
  36. }
  37. /// <summary>
  38. /// This property is not relevant to this class.
  39. /// </summary>
  40. [Browsable(false)]
  41. public override DockStyle Dock
  42. {
  43. get { return base.Dock; }
  44. set { base.Dock = value; }
  45. }
  46. /// <summary>
  47. /// This property is not relevant to this class.
  48. /// </summary>
  49. [Browsable(false)]
  50. public override AnchorStyles Anchor
  51. {
  52. get { return base.Anchor; }
  53. set { base.Anchor = value; }
  54. }
  55. /// <summary>
  56. /// This property is not relevant to this class.
  57. /// </summary>
  58. [Browsable(false)]
  59. public new bool GrowToBottom
  60. {
  61. get { return base.GrowToBottom; }
  62. set { base.GrowToBottom = value; }
  63. }
  64. /// <summary>
  65. /// This property is not relevant to this class.
  66. /// </summary>
  67. [Browsable(false)]
  68. public new ShiftMode ShiftMode
  69. {
  70. get { return base.ShiftMode; }
  71. set { base.ShiftMode = value; }
  72. }
  73. /// <inheritdoc/>
  74. [DefaultValue(false)]
  75. public new bool CanBreak
  76. {
  77. get { return base.CanBreak; }
  78. set { base.CanBreak = value; }
  79. }
  80. /// <summary>
  81. /// This property is not relevant to this class.
  82. /// </summary>
  83. [Browsable(false)]
  84. public new BreakableComponent BreakTo
  85. {
  86. get { return base.BreakTo; }
  87. set { base.BreakTo = value; }
  88. }
  89. internal bool CanDelete
  90. {
  91. get
  92. {
  93. if (Page != null)
  94. {
  95. // do not delete the sole band on the page
  96. ObjectCollection pageObjects = Page.AllObjects;
  97. ObjectCollection bands = new ObjectCollection();
  98. foreach (Base obj in pageObjects)
  99. {
  100. // fix: it was possible to delete the band if it has a child band
  101. if (obj is BandBase && (obj == this || !(obj is ChildBand)))
  102. bands.Add(obj);
  103. }
  104. return bands.Count > 1;
  105. }
  106. else
  107. return false;
  108. }
  109. }
  110. internal float DesignWidth
  111. {
  112. get
  113. {
  114. ReportPage page = Page as ReportPage;
  115. if (page != null && page.ExtraDesignWidth)
  116. {
  117. if (page.Columns.Count <= 1 || !IsColumnDependentBand)
  118. return Width * 5;
  119. }
  120. return Width;
  121. }
  122. }
  123. #endregion
  124. #region Public Methods
  125. /// <inheritdoc/>
  126. public override void DrawSelection(FRPaintEventArgs e)
  127. {
  128. DrawSelectionPoint(e, Pens.Black, Brushes.White, Left + Width / 2, Top + Height + 2);
  129. DrawSelectionPoint(e, Pens.Black, Brushes.White, Left + Width / 2, Top + 2);
  130. }
  131. /// <inheritdoc/>
  132. public override bool PointInObject(PointF point)
  133. {
  134. if (IsDesigning)
  135. {
  136. if (ReportWorkspace.ClassicView)
  137. return new RectangleF(Left, Top - (HeaderSize - 1), DesignWidth, Height + HeaderSize - 1).Contains(point);
  138. else
  139. return new RectangleF(Left, Top, DesignWidth, Height).Contains(point);
  140. }
  141. return AbsBounds.Contains(point);
  142. }
  143. /// <inheritdoc/>
  144. public override void HandleMouseDown(FRMouseEventArgs e)
  145. {
  146. base.HandleMouseDown(e);
  147. if (e.handled)
  148. {
  149. if (e.modifierKeys != Keys.Shift)
  150. {
  151. e.mode = WorkspaceMode2.SelectionRect;
  152. e.activeObject = this;
  153. }
  154. }
  155. }
  156. /// <inheritdoc/>
  157. public override void HandleMouseHover(FRMouseEventArgs e)
  158. {
  159. base.HandleMouseHover(e);
  160. if (e.handled)
  161. e.cursor = Cursors.Default;
  162. }
  163. /// <inheritdoc/>
  164. public override void HandleMouseMove(FRMouseEventArgs e)
  165. {
  166. PointF point = new PointF(e.x, e.y);
  167. if (e.button == MouseButtons.None)
  168. {
  169. e.sizingPoint = SizingPoint.None;
  170. if (point.Y > Bounds.Bottom && point.Y < Bounds.Bottom + 4)
  171. {
  172. e.mode = WorkspaceMode2.Size;
  173. e.sizingPoint = SizingPoint.BottomCenter;
  174. e.cursor = Cursors.HSplit;
  175. e.handled = true;
  176. }
  177. 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)
  178. {
  179. e.mode = WorkspaceMode2.Size;
  180. e.sizingPoint = SizingPoint.TopCenter;
  181. e.cursor = Cursors.HSplit;
  182. e.handled = true;
  183. }
  184. }
  185. else
  186. {
  187. if (e.activeObject == this && e.mode == WorkspaceMode2.Size)
  188. {
  189. if (e.sizingPoint == SizingPoint.BottomCenter)
  190. {
  191. Height += e.delta.Y;
  192. FixHeight();
  193. }
  194. if (e.sizingPoint == SizingPoint.TopCenter)
  195. {
  196. Height -= e.delta.Y;
  197. FixHeightWithComponentsShift(e.delta.Y);
  198. }
  199. e.handled = true;
  200. }
  201. }
  202. }
  203. /// <inheritdoc/>
  204. public override void HandleMouseUp(FRMouseEventArgs e)
  205. {
  206. if (Report == null)
  207. return;
  208. if (e.mode == WorkspaceMode2.SelectionRect)
  209. {
  210. ObjectCollection selectedList = new ObjectCollection();
  211. // find objects inside the selection rect
  212. for (int i = 0; i < Report.Designer.Objects.Count; i++)
  213. {
  214. Base c = Report.Designer.Objects[i];
  215. if (c is ComponentBase && !(c is BandBase))
  216. {
  217. e.handled = false;
  218. (c as ComponentBase).HandleMouseUp(e);
  219. // object is inside
  220. if (e.handled)
  221. selectedList.Add(c);
  222. }
  223. }
  224. if (selectedList.Count > 0)
  225. selectedList.CopyTo(Report.Designer.SelectedObjects);
  226. }
  227. FixHeight();
  228. }
  229. /// <inheritdoc/>
  230. public override SizeF GetPreferredSize()
  231. {
  232. SizeF result = new SizeF(0, 0);
  233. switch (ReportWorkspace.Grid.GridUnits)
  234. {
  235. case PageUnits.Millimeters:
  236. result = new SizeF(Units.Millimeters * 10, Units.Millimeters * 10);
  237. break;
  238. case PageUnits.Centimeters:
  239. result = new SizeF(Units.Centimeters * 1, Units.Centimeters * 1);
  240. break;
  241. case PageUnits.Inches:
  242. result = new SizeF(Units.Inches * 0.5f, Units.Inches * 0.5f);
  243. break;
  244. case PageUnits.HundrethsOfInch:
  245. result = new SizeF(Units.HundrethsOfInch * 50, Units.HundrethsOfInch * 50);
  246. break;
  247. }
  248. return result;
  249. }
  250. /// <inheritdoc/>
  251. public override void Delete()
  252. {
  253. if (CanDelete)
  254. Dispose();
  255. }
  256. internal virtual string GetInfoText()
  257. {
  258. return "";
  259. }
  260. internal void DrawBandHeader(Graphics g, RectangleF rect, bool drawTopLine)
  261. {
  262. if (Report == null)
  263. return;
  264. Color color1 = Color.Empty;
  265. if (this is GroupHeaderBand || this is GroupFooterBand)
  266. color1 = Color.FromArgb(144, 228, 0);
  267. else if (this is DataBand)
  268. color1 = Color.FromArgb(255, 144, 0);
  269. else
  270. color1 = UIStyleUtils.GetGrayColor(Report.Designer.UIStyle);
  271. Color color2 = Color.FromArgb(100, color1);
  272. Color color3 = Color.FromArgb(180, Color.White);
  273. Color color4 = Color.Transparent;
  274. g.FillRectangle(Brushes.White, rect);
  275. using (LinearGradientBrush b = new LinearGradientBrush(rect, color1, color2, 90))
  276. {
  277. g.FillRectangle(b, rect);
  278. }
  279. rect.Height /= 3;
  280. using (LinearGradientBrush b = new LinearGradientBrush(rect, color3, color4, 90))
  281. {
  282. g.FillRectangle(b, rect);
  283. }
  284. if (drawTopLine)
  285. {
  286. using (Pen p = new Pen(color1))
  287. {
  288. g.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Top);
  289. }
  290. }
  291. }
  292. /// <inheritdoc/>
  293. public override ContextMenuBase GetContextMenu()
  294. {
  295. return new BandBaseMenu(Report.Designer);
  296. }
  297. /// <inheritdoc/>
  298. public override void Draw(FRPaintEventArgs e)
  299. {
  300. if (Report == null)
  301. return;
  302. UpdateWidth();
  303. if (IsDesigning)
  304. {
  305. IGraphics g = e.Graphics;
  306. RectangleF bounds = Bounds;
  307. bounds.X *= e.ScaleX;
  308. bounds.Y *= e.ScaleY;
  309. bounds.Width = DesignWidth * e.ScaleX;
  310. bounds.Height *= e.ScaleY;
  311. if (ReportWorkspace.ClassicView && Width != 0)
  312. {
  313. RectangleF fillRect = new RectangleF(bounds.Left, bounds.Top - (BandBase.HeaderSize - 1) * e.ScaleY,
  314. bounds.Width, (BandBase.HeaderSize - 1) * e.ScaleY);
  315. if (bounds.Top == BandBase.HeaderSize)
  316. {
  317. fillRect.Y = 0;
  318. fillRect.Height += e.ScaleY;
  319. }
  320. DrawBandHeader(g.Graphics, fillRect, true);
  321. ObjectInfo info = RegisteredObjects.FindObject(this);
  322. string text = Res.Get(info.Text);
  323. if (GetInfoText() != "")
  324. text += ": " + GetInfoText();
  325. fillRect.X += 4;
  326. using (Font f = new Font(DrawUtils.DefaultFont.Name, DrawUtils.DefaultFont.Size * 96 / DrawUtils.ScreenDpi * Report.Designer.ZoomDpi))
  327. TextRenderer.DrawText(g.Graphics, text, f,
  328. Rectangle.Round(fillRect), SystemColors.WindowText, TextFormatFlags.VerticalCenter | TextFormatFlags.PreserveGraphicsTranslateTransform);
  329. }
  330. g.FillRectangle(SystemBrushes.Window, bounds.Left, (int)Math.Round(bounds.Top),
  331. bounds.Width, bounds.Height + (ReportWorkspace.ClassicView ? 1 : 4));
  332. DrawBackground(e);
  333. if (ReportWorkspace.ShowGrid)
  334. ReportWorkspace.Grid.Draw(g.Graphics, bounds, e.ScaleX);
  335. if (!ReportWorkspace.ClassicView)
  336. {
  337. Pen pen = e.Cache.GetPen(Color.Silver, 1, DashStyle.Dot);
  338. g.DrawLine(pen, bounds.Left, bounds.Bottom + 1, bounds.Right + 1, bounds.Bottom + 1);
  339. g.DrawLine(pen, bounds.Left + 1, bounds.Bottom + 2, bounds.Right + 1, bounds.Bottom + 2);
  340. g.DrawLine(pen, bounds.Left, bounds.Bottom + 3, bounds.Right + 1, bounds.Bottom + 3);
  341. }
  342. }
  343. else
  344. {
  345. DrawBackground(e);
  346. Border.Draw(e, new RectangleF(AbsLeft, AbsTop, Width, Height));
  347. }
  348. }
  349. internal void FixHeight()
  350. {
  351. float maxHeight = Height;
  352. foreach (ReportComponentBase c in Objects)
  353. {
  354. if (c.Bottom > maxHeight)
  355. maxHeight = c.Bottom;
  356. }
  357. if (maxHeight < 0)
  358. maxHeight = 0;
  359. Height = maxHeight;
  360. }
  361. internal void FixHeightWithComponentsShift(float deltaY)
  362. {
  363. float minTop = Height;
  364. float maxBottom = 0;
  365. float minHeight = Height;
  366. // Calculate minimum top of all components on this band.
  367. foreach (ReportComponentBase component in Objects)
  368. {
  369. if (component.Top < minTop)
  370. {
  371. minTop = component.Top;
  372. }
  373. }
  374. // Calculate maximum bottom of all components on this band.
  375. foreach (ReportComponentBase component in Objects)
  376. {
  377. if (component.Bottom > maxBottom)
  378. {
  379. maxBottom = component.Bottom;
  380. }
  381. }
  382. // Calculate minimum height of band with components shift.
  383. minHeight = maxBottom - minTop;
  384. // Minimum height with compenents shift can't be negative.
  385. if (minHeight < 0)
  386. {
  387. minHeight = 0;
  388. }
  389. // Prevent incorrect movement of objects when mouse moves too fast.
  390. if (minTop < deltaY)
  391. {
  392. deltaY = minTop;
  393. }
  394. // Size of band should be decreased.
  395. if (deltaY > 0)
  396. {
  397. // There is enough place to move components up.
  398. if (minTop > 0)
  399. {
  400. // Move all components up.
  401. foreach (ReportComponentBase component in Objects)
  402. {
  403. component.Top -= deltaY;
  404. }
  405. }
  406. }
  407. else
  408. {
  409. // Move all components down.
  410. foreach (ReportComponentBase component in Objects)
  411. {
  412. component.Top -= deltaY;
  413. }
  414. }
  415. // Height can't be less then minHeight.
  416. if (Height < minHeight)
  417. {
  418. Height = minHeight;
  419. }
  420. }
  421. #endregion
  422. }
  423. }