BandBase.DesignExt.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. /// <summary>
  74. /// This property is not relevant to this class.
  75. /// </summary>
  76. [DefaultValue(false)]
  77. public new bool CanBreak
  78. {
  79. get { return base.CanBreak; }
  80. set { base.CanBreak = value; }
  81. }
  82. /// <summary>
  83. /// This property is not relevant to this class.
  84. /// </summary>
  85. [Browsable(false)]
  86. public new BreakableComponent BreakTo
  87. {
  88. get { return base.BreakTo; }
  89. set { base.BreakTo = value; }
  90. }
  91. internal bool CanDelete
  92. {
  93. get
  94. {
  95. if (Page != null)
  96. {
  97. // do not delete the sole band on the page
  98. ObjectCollection pageObjects = Page.AllObjects;
  99. ObjectCollection bands = new ObjectCollection();
  100. foreach (Base obj in pageObjects)
  101. {
  102. // fix: it was possible to delete the band if it has a child band
  103. if (obj is BandBase && (obj == this || !(obj is ChildBand)))
  104. bands.Add(obj);
  105. }
  106. return bands.Count > 1;
  107. }
  108. else
  109. return false;
  110. }
  111. }
  112. internal float DesignWidth
  113. {
  114. get
  115. {
  116. ReportPage page = Page as ReportPage;
  117. if (page != null && page.ExtraDesignWidth)
  118. {
  119. if (page.Columns.Count <= 1 || !IsColumnDependentBand)
  120. return Width * 5;
  121. }
  122. return Width;
  123. }
  124. }
  125. #endregion
  126. #region Public Methods
  127. /// <inheritdoc/>
  128. public override void DrawSelection(FRPaintEventArgs e)
  129. {
  130. DrawSelectionPoint(e, Pens.Black, Brushes.White, Left + Width / 2, Top + Height + 2);
  131. DrawSelectionPoint(e, Pens.Black, Brushes.White, Left + Width / 2, Top + 2);
  132. }
  133. /// <inheritdoc/>
  134. public override bool PointInObject(PointF point)
  135. {
  136. if (IsDesigning)
  137. {
  138. if (ReportWorkspace.ClassicView)
  139. return new RectangleF(Left, Top - (HeaderSize - 1), DesignWidth, Height + HeaderSize - 1).Contains(point);
  140. else
  141. return new RectangleF(Left, Top, DesignWidth, Height).Contains(point);
  142. }
  143. return AbsBounds.Contains(point);
  144. }
  145. /// <inheritdoc/>
  146. public override void HandleMouseDown(FRMouseEventArgs e)
  147. {
  148. base.HandleMouseDown(e);
  149. if (e.handled)
  150. {
  151. if (e.modifierKeys != Keys.Shift)
  152. {
  153. e.mode = WorkspaceMode2.SelectionRect;
  154. e.activeObject = this;
  155. }
  156. }
  157. }
  158. /// <inheritdoc/>
  159. public override void HandleMouseHover(FRMouseEventArgs e)
  160. {
  161. base.HandleMouseHover(e);
  162. if (e.handled)
  163. e.cursor = Cursors.Default;
  164. }
  165. /// <inheritdoc/>
  166. public override void HandleMouseMove(FRMouseEventArgs e)
  167. {
  168. PointF point = new PointF(e.x, e.y);
  169. if (e.button == MouseButtons.None)
  170. {
  171. e.sizingPoint = SizingPoint.None;
  172. if (point.Y > Bounds.Bottom && point.Y < Bounds.Bottom + 4)
  173. {
  174. e.mode = WorkspaceMode2.Size;
  175. e.sizingPoint = SizingPoint.BottomCenter;
  176. e.cursor = Cursors.HSplit;
  177. e.handled = true;
  178. }
  179. 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)
  180. {
  181. e.mode = WorkspaceMode2.Size;
  182. e.sizingPoint = SizingPoint.TopCenter;
  183. e.cursor = Cursors.HSplit;
  184. e.handled = true;
  185. }
  186. }
  187. else
  188. {
  189. if (e.activeObject == this && e.mode == WorkspaceMode2.Size)
  190. {
  191. if (e.sizingPoint == SizingPoint.BottomCenter)
  192. {
  193. Height += e.delta.Y;
  194. FixHeight();
  195. }
  196. if (e.sizingPoint == SizingPoint.TopCenter)
  197. {
  198. Height -= e.delta.Y;
  199. FixHeightWithComponentsShift(e.delta.Y);
  200. }
  201. e.handled = true;
  202. }
  203. }
  204. }
  205. /// <inheritdoc/>
  206. public override void HandleMouseUp(FRMouseEventArgs e)
  207. {
  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. Color color1 = Color.Empty;
  263. if (this is GroupHeaderBand || this is GroupFooterBand)
  264. color1 = Color.FromArgb(144, 228, 0);
  265. else if (this is DataBand)
  266. color1 = Color.FromArgb(255, 144, 0);
  267. else
  268. {
  269. // select appropriate gray color
  270. switch (Report.Designer.UIStyle)
  271. {
  272. case UIStyle.VisualStudio2005:
  273. color1 = SystemColors.Control;
  274. break;
  275. case UIStyle.Office2003:
  276. color1 = Color.FromArgb(145, 180, 230);
  277. break;
  278. case UIStyle.Office2007Blue:
  279. color1 = Color.FromArgb(170, 210, 255);
  280. break;
  281. case UIStyle.Office2007Silver:
  282. #if !MONO
  283. case UIStyle.Office2010Silver:
  284. case UIStyle.Office2013:
  285. case UIStyle.VisualStudio2012Light:
  286. #endif
  287. color1 = Color.FromArgb(192, 193, 194);
  288. break;
  289. #if !MONO
  290. case UIStyle.VisualStudio2010:
  291. color1 = Color.FromArgb(188, 199, 216);
  292. break;
  293. #endif
  294. case UIStyle.Office2007Black:
  295. color1 = Color.FromArgb(143, 150, 160);
  296. break;
  297. case UIStyle.VistaGlass:
  298. color1 = Color.FromArgb(190, 200, 227);
  299. break;
  300. }
  301. }
  302. Color color2 = Color.FromArgb(100, color1);
  303. Color color3 = Color.FromArgb(180, Color.White);
  304. Color color4 = Color.Transparent;
  305. g.FillRectangle(Brushes.White, rect);
  306. using (LinearGradientBrush b = new LinearGradientBrush(rect, color1, color2, 90))
  307. {
  308. g.FillRectangle(b, rect);
  309. }
  310. rect.Height /= 3;
  311. using (LinearGradientBrush b = new LinearGradientBrush(rect, color3, color4, 90))
  312. {
  313. g.FillRectangle(b, rect);
  314. }
  315. if (drawTopLine)
  316. {
  317. using (Pen p = new Pen(color1))
  318. {
  319. g.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Top);
  320. }
  321. }
  322. }
  323. /// <inheritdoc/>
  324. public override ContextMenuBase GetContextMenu()
  325. {
  326. return new BandBaseMenu(Report.Designer);
  327. }
  328. /// <inheritdoc/>
  329. public override void Draw(FRPaintEventArgs e)
  330. {
  331. UpdateWidth();
  332. if (IsDesigning)
  333. {
  334. IGraphics g = e.Graphics;
  335. RectangleF bounds = Bounds;
  336. bounds.X *= e.ScaleX;
  337. bounds.Y *= e.ScaleY;
  338. bounds.Width = DesignWidth * e.ScaleX;
  339. bounds.Height *= e.ScaleY;
  340. if (ReportWorkspace.ClassicView && Width != 0)
  341. {
  342. RectangleF fillRect = new RectangleF(bounds.Left, bounds.Top - (BandBase.HeaderSize - 1) * e.ScaleY,
  343. bounds.Width, (BandBase.HeaderSize - 1) * e.ScaleY);
  344. if (bounds.Top == BandBase.HeaderSize)
  345. {
  346. fillRect.Y = 0;
  347. fillRect.Height += e.ScaleY;
  348. }
  349. DrawBandHeader(g.Graphics, fillRect, true);
  350. ObjectInfo info = RegisteredObjects.FindObject(this);
  351. string text = Res.Get(info.Text);
  352. if (GetInfoText() != "")
  353. text += ": " + GetInfoText();
  354. fillRect.X += 4;
  355. using (Font f = new Font(DrawUtils.Default96Font.Name, DrawUtils.Default96Font.Size * Report.Designer.ZoomDpi, FontStyle.Regular))
  356. TextRenderer.DrawText(g.Graphics, text, f,
  357. Rectangle.Round(fillRect), SystemColors.WindowText, TextFormatFlags.VerticalCenter);
  358. }
  359. g.FillRectangle(SystemBrushes.Window, bounds.Left, (int)Math.Round(bounds.Top),
  360. bounds.Width, bounds.Height + (ReportWorkspace.ClassicView ? 1 : 4));
  361. DrawBackground(e);
  362. if (ReportWorkspace.ShowGrid)
  363. ReportWorkspace.Grid.Draw(g.Graphics, bounds, e.ScaleX);
  364. if (!ReportWorkspace.ClassicView)
  365. {
  366. Pen pen = e.Cache.GetPen(Color.Silver, 1, DashStyle.Dot);
  367. g.DrawLine(pen, bounds.Left, bounds.Bottom + 1, bounds.Right + 1, bounds.Bottom + 1);
  368. g.DrawLine(pen, bounds.Left + 1, bounds.Bottom + 2, bounds.Right + 1, bounds.Bottom + 2);
  369. g.DrawLine(pen, bounds.Left, bounds.Bottom + 3, bounds.Right + 1, bounds.Bottom + 3);
  370. }
  371. }
  372. else
  373. {
  374. DrawBackground(e);
  375. Border.Draw(e, new RectangleF(AbsLeft, AbsTop, Width, Height));
  376. }
  377. }
  378. #endregion
  379. }
  380. }