Ruler.cs 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  1. using FastReport.Editor;
  2. using FastReport.TypeConverters;
  3. using FastReport.Utils;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Drawing.Drawing2D;
  9. using System.Windows.Forms;
  10. namespace FastReport.Design.PageDesigners.Page
  11. {
  12. internal class RulerBase : UserControl
  13. {
  14. protected ToolTip toolTip;
  15. private ReportPageDesigner pageDesigner;
  16. private float offset;
  17. public float Offset
  18. {
  19. get { return offset; }
  20. set { offset = value; }
  21. }
  22. public ReportWorkspace Workspace
  23. {
  24. get { return pageDesigner.Workspace; }
  25. }
  26. public ReportPageDesigner PageDesigner
  27. {
  28. get { return pageDesigner; }
  29. }
  30. public Designer Designer
  31. {
  32. get { return pageDesigner.Designer; }
  33. }
  34. protected bool CheckGridStep(ref float kx, ref float ky)
  35. {
  36. bool al = ReportWorkspace.SnapToGrid;
  37. if (ModifierKeys == Keys.Alt)
  38. al = !al;
  39. bool result = true;
  40. float grid = ReportWorkspace.Grid.SnapSize;
  41. if (al)
  42. {
  43. result = kx >= grid || kx <= -grid || ky >= grid || ky <= -grid;
  44. if (result)
  45. {
  46. kx = (int)(kx / grid) * grid;
  47. ky = (int)(ky / grid) * grid;
  48. }
  49. }
  50. return result;
  51. }
  52. public RulerBase(ReportPageDesigner pd) : base()
  53. {
  54. pageDesigner = pd;
  55. toolTip = new ToolTip();
  56. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  57. SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  58. }
  59. }
  60. internal class HorzRuler : RulerBase
  61. {
  62. private PointF lastMousePoint;
  63. private bool mouseDown;
  64. private bool mouseMoved;
  65. private int activeGuide;
  66. private bool saveAutoGuides;
  67. private void DrawRuler(Graphics g, float start, float size)
  68. {
  69. Font font = new Font("Tahoma", 6f * this.FontDpiMultiplier());
  70. Brush brush = SystemBrushes.WindowText;
  71. Pen pen = SystemPens.WindowText;
  72. int w5 = 5;
  73. int w10 = 10;
  74. float dx = (ReportWorkspace.Grid.GridUnits == PageUnits.Millimeters || ReportWorkspace.Grid.GridUnits == PageUnits.Centimeters ?
  75. Units.Millimeters : Units.TenthsOfInch) * Designer.ZoomDpi;
  76. string s = (((int)Math.Round(size / dx)) / 10).ToString();
  77. float maxw = g.MeasureString(s, font).Width;
  78. float i = start;
  79. int i1 = 0;
  80. while (i < start + size)
  81. {
  82. int h = 0;
  83. if (i1 == 0)
  84. h = 0;
  85. else if (i1 % w10 == 0)
  86. h = 6;
  87. else if (i1 % w5 == 0)
  88. h = 4;
  89. else
  90. h = 2;
  91. if (h == 2 && dx * w10 < this.LogicalToDevice(41))
  92. h = 0;
  93. if (h == 4 && dx * w10 < this.LogicalToDevice(21))
  94. h = 0;
  95. int w = 0;
  96. if (h == 6)
  97. {
  98. if (maxw > dx * w10 * 1.5f)
  99. w = w10 * 4;
  100. else if (maxw > dx * w10 * 0.7f)
  101. w = w10 * 2;
  102. else
  103. w = w10;
  104. }
  105. if (w != 0 && i1 % w == 0)
  106. {
  107. if (ReportWorkspace.Grid.GridUnits == PageUnits.Millimeters)
  108. s = (i1).ToString();
  109. else if (ReportWorkspace.Grid.GridUnits == PageUnits.HundrethsOfInch)
  110. s = (i1 * 10).ToString();
  111. else
  112. s = (i1 / 10).ToString();
  113. SizeF sz = g.MeasureString(s, font);
  114. g.DrawString(s, font, brush, new PointF(Offset + i - sz.Width / 2 + 1, this.LogicalToDevice(7)));
  115. }
  116. else if (h != 0)
  117. {
  118. g.DrawLine(pen,
  119. Offset + i, this.LogicalToDevice(6 + (13 - h) / 2),
  120. Offset + i, this.LogicalToDevice(6 + (13 - h) / 2 + h - 1));
  121. }
  122. i += dx;
  123. i1++;
  124. }
  125. }
  126. private void DrawRulerRtl(Graphics g, float start, float size)
  127. {
  128. Font font = new Font("Tahoma", 6f * this.FontDpiMultiplier());
  129. Brush brush = SystemBrushes.WindowText;
  130. Pen pen = SystemPens.WindowText;
  131. int w5 = 5;
  132. int w10 = 10;
  133. float dx = (ReportWorkspace.Grid.GridUnits == PageUnits.Millimeters || ReportWorkspace.Grid.GridUnits == PageUnits.Centimeters ?
  134. Units.Millimeters : Units.TenthsOfInch) * Designer.ZoomDpi;
  135. string s = (((int)Math.Round(size / dx)) / 10).ToString();
  136. float maxw = g.MeasureString(s, font).Width;
  137. float i = start + size;
  138. int i1 = 0;
  139. while (i > start)
  140. {
  141. int h = 0;
  142. if (i1 == 0)
  143. h = 0;
  144. else if (i1 % w10 == 0)
  145. h = 6;
  146. else if (i1 % w5 == 0)
  147. h = 4;
  148. else
  149. h = 2;
  150. if (h == 2 && dx * w10 < this.LogicalToDevice(41))
  151. h = 0;
  152. if (h == 4 && dx * w10 < this.LogicalToDevice(21))
  153. h = 0;
  154. int w = 0;
  155. if (h == 6)
  156. {
  157. if (maxw > dx * w10 * 1.5f)
  158. w = w10 * 4;
  159. else if (maxw > dx * w10 * 0.7f)
  160. w = w10 * 2;
  161. else
  162. w = w10;
  163. }
  164. if (w != 0 && i1 % w == 0)
  165. {
  166. if (ReportWorkspace.Grid.GridUnits == PageUnits.Millimeters)
  167. s = (i1).ToString();
  168. else if (ReportWorkspace.Grid.GridUnits == PageUnits.HundrethsOfInch)
  169. s = (i1 * 10).ToString();
  170. else
  171. s = (i1 / 10).ToString();
  172. SizeF sz = g.MeasureString(s, font);
  173. g.DrawString(s, font, brush, new PointF(Offset + i - sz.Width / 2 + 1, this.LogicalToDevice(7)));
  174. }
  175. else if (h != 0)
  176. {
  177. g.DrawLine(pen,
  178. Offset + i, this.LogicalToDevice(6 + (13 - h) / 2),
  179. Offset + i, this.LogicalToDevice(6 + (13 - h) / 2 + h - 1));
  180. }
  181. i -= dx;
  182. i1++;
  183. }
  184. }
  185. private void DrawGuides(Graphics g)
  186. {
  187. FloatCollection guides = Workspace.Page.Guides;
  188. if (guides == null)
  189. return;
  190. g.SmoothingMode = SmoothingMode.HighQuality;
  191. int _4 = this.LogicalToDevice(4);
  192. int _6 = this.LogicalToDevice(6);
  193. int _8 = this.LogicalToDevice(8);
  194. int _32 = this.LogicalToDevice(32);
  195. if (guides.Count > activeGuide && activeGuide != -1)
  196. {
  197. toolTip.Show(Converter.ToString((Workspace.Page.LeftMargin * Units.Millimeters + guides[activeGuide]) / ReportWorkspace.Grid.SnapSize * 10 / 4, typeof(PaperConverter))
  198. + " | " +
  199. Converter.ToString((Workspace.Page.PaperWidth * Units.Millimeters - Workspace.Page.LeftMargin * Units.Millimeters - guides[activeGuide]) / ReportWorkspace.Grid.SnapSize * 10 / 4, typeof(PaperConverter)),
  200. this, (int)Math.Round(Offset + guides[activeGuide] * Designer.ZoomDpi - 4), _32
  201. );
  202. }
  203. if (activeGuide == -1)
  204. toolTip.Hide(this);
  205. int y = this.LogicalToDevice(16);
  206. for (int i = 0; i < guides.Count; i++)
  207. {
  208. int x = (int)Math.Round(Offset + guides[i] * Designer.ZoomDpi - _4);
  209. g.FillPolygon(i == activeGuide ? SystemBrushes.Highlight : Brushes.Black, new Point[]
  210. {
  211. new Point(x, y), new Point(x + _8, y), new Point(x + _4, y + _6)
  212. });
  213. }
  214. }
  215. private void MoveGuide(float kx)
  216. {
  217. Workspace.Guides.MoveVGuide(activeGuide, kx);
  218. float f = Workspace.Page.Guides[activeGuide];
  219. f += kx;
  220. Workspace.Page.Guides[activeGuide] = Converter.DecreasePrecision(f, 2);
  221. Workspace.Refresh();
  222. Refresh();
  223. }
  224. private void FixGuide(bool remove)
  225. {
  226. float f = Workspace.Page.Guides[activeGuide];
  227. if (remove || f < 0 || f > Workspace.WorkspaceSize.Width / Designer.ZoomDpi)
  228. Workspace.Page.Guides.RemoveAt(activeGuide);
  229. activeGuide = -1;
  230. Refresh();
  231. }
  232. protected override void OnPaint(PaintEventArgs e)
  233. {
  234. if (Workspace.Locked)
  235. return;
  236. int w = Workspace.WorkspaceSize.Width;
  237. Graphics g = e.Graphics;
  238. g.SetClip(new RectangleF(Height, 0, Width - Height, Height));
  239. g.FillRectangle(SystemBrushes.Window, new RectangleF(Offset, this.LogicalToDevice(5), w, Height - this.LogicalToDevice(10)));
  240. if (Config.RightToLeft)
  241. {
  242. DrawRulerRtl(g, 0, w);
  243. }
  244. else
  245. {
  246. DrawRuler(g, 0, w);
  247. }
  248. DrawGuides(g);
  249. }
  250. protected override void OnMouseDown(MouseEventArgs e)
  251. {
  252. base.OnMouseDown(e);
  253. if (Workspace.Locked)
  254. return;
  255. float scale = Designer.ZoomDpi;
  256. lastMousePoint = new PointF(e.X / scale, e.Y / scale);
  257. mouseDown = true;
  258. mouseMoved = false;
  259. if (activeGuide != -1)
  260. Workspace.Guides.BeforeMoveVGuide(activeGuide);
  261. saveAutoGuides = ReportWorkspace.AutoGuides;
  262. ReportWorkspace.AutoGuides = false;
  263. }
  264. protected override void OnMouseMove(MouseEventArgs e)
  265. {
  266. base.OnMouseMove(e);
  267. if (Workspace.Locked)
  268. return;
  269. float scale = Designer.ZoomDpi;
  270. if (e.Button == MouseButtons.None)
  271. {
  272. // find guide
  273. FloatCollection guides = Workspace.Page.Guides;
  274. if (guides == null)
  275. return;
  276. float x = (e.X - Offset) / scale;
  277. activeGuide = -1;
  278. for (int i = 0; i < guides.Count; i++)
  279. {
  280. if (x > guides[i] - 5 && x < guides[i] + 5)
  281. {
  282. activeGuide = i;
  283. break;
  284. }
  285. }
  286. Refresh();
  287. }
  288. else if (e.Button == MouseButtons.Left)
  289. {
  290. if (activeGuide == -1)
  291. return;
  292. float kx = e.X / scale - lastMousePoint.X;
  293. float ky = e.Y / scale - lastMousePoint.Y;
  294. if (!CheckGridStep(ref kx, ref ky))
  295. return;
  296. mouseMoved = true;
  297. MoveGuide(kx);
  298. lastMousePoint.X += kx;
  299. lastMousePoint.Y += ky;
  300. }
  301. }
  302. protected override void OnMouseUp(MouseEventArgs e)
  303. {
  304. base.OnMouseUp(e);
  305. if (Workspace.Locked || !mouseDown)
  306. return;
  307. int _5 = this.LogicalToDevice(5);
  308. int _20 = this.LogicalToDevice(20);
  309. ReportWorkspace.AutoGuides = saveAutoGuides;
  310. mouseDown = false;
  311. if (mouseMoved)
  312. {
  313. FixGuide(e.Y < -_5 || e.Y > Height + _5);
  314. Workspace.Designer.SetModified(null, "MoveGuide");
  315. }
  316. else
  317. {
  318. // create new guide
  319. float x = (e.X - Offset) / Designer.ZoomDpi;
  320. if (x < Workspace.WorkspaceSize.Width && e.Y > _5 && e.Y < _20)
  321. {
  322. if (ReportWorkspace.SnapToGrid)
  323. x = (int)(x / ReportWorkspace.Grid.SnapSize) * ReportWorkspace.Grid.SnapSize;
  324. if (Workspace.Page.Guides == null)
  325. Workspace.Page.Guides = new FloatCollection();
  326. Workspace.Page.Guides.Add(x);
  327. Workspace.Designer.SetModified(null, "AddGuide");
  328. }
  329. }
  330. }
  331. protected override void OnMouseLeave(EventArgs e)
  332. {
  333. base.OnMouseLeave(e);
  334. if (Workspace.Locked)
  335. return;
  336. if (!mouseDown && activeGuide != -1)
  337. {
  338. activeGuide = -1;
  339. Refresh();
  340. }
  341. }
  342. public HorzRuler(ReportPageDesigner pd) : base(pd)
  343. {
  344. activeGuide = -1;
  345. }
  346. }
  347. internal class VertRuler : RulerBase
  348. {
  349. private PointF lastMousePoint;
  350. private bool mouseDown;
  351. private bool mouseMoved;
  352. private int activeGuide;
  353. private BandBase activeBand;
  354. private bool resizing;
  355. private bool saveAutoGuides;
  356. private void DrawRuler(Graphics g, float start, float size)
  357. {
  358. Font font = new Font("Tahoma", 6f * this.FontDpiMultiplier());
  359. Brush brush = SystemBrushes.WindowText;
  360. Pen pen = SystemPens.WindowText;
  361. int w5 = 5;
  362. int w10 = 10;
  363. float dx = (ReportWorkspace.Grid.GridUnits == PageUnits.Millimeters || ReportWorkspace.Grid.GridUnits == PageUnits.Centimeters ?
  364. Units.Millimeters : Units.TenthsOfInch) * Designer.ZoomDpi;
  365. string s = (((int)Math.Round(size / dx)) / 10).ToString();
  366. float maxw = g.MeasureString(s, font).Width;
  367. float i = start;
  368. int i1 = 0;
  369. while (i < start + size)
  370. {
  371. int h = 0;
  372. if (i1 == 0)
  373. h = 0;
  374. else if (i1 % w10 == 0)
  375. h = 6;
  376. else if (i1 % w5 == 0)
  377. h = 4;
  378. else
  379. h = 2;
  380. if (h == 2 && dx * w10 < this.LogicalToDevice(41))
  381. h = 0;
  382. if (h == 4 && dx * w10 < this.LogicalToDevice(21))
  383. h = 0;
  384. int w = 0;
  385. if (h == 6)
  386. {
  387. if (maxw > dx * w10 * 1.5f)
  388. w = w10 * 4;
  389. else if (maxw > dx * w10 * 0.7f)
  390. w = w10 * 2;
  391. else
  392. w = w10;
  393. }
  394. if (w != 0 && i1 % w == 0)
  395. {
  396. if (ReportWorkspace.Grid.GridUnits == PageUnits.Millimeters)
  397. s = (i1).ToString();
  398. else if (ReportWorkspace.Grid.GridUnits == PageUnits.HundrethsOfInch)
  399. s = (i1 * 10).ToString();
  400. else
  401. s = (i1 / 10).ToString();
  402. SizeF sz = g.MeasureString(s, font);
  403. PointF p = new PointF(Width - sz.Height - this.LogicalToDevice(7), Offset + i + sz.Width / 2);
  404. GraphicsState state = g.Save();
  405. g.TranslateTransform(p.X + sz.Height / 2, p.Y + sz.Width / 2);
  406. g.RotateTransform(-90);
  407. p.X /= 2;
  408. p.Y = -sz.Height / 2;
  409. g.DrawString(s, font, brush, p);
  410. g.Restore(state);
  411. }
  412. else if (h != 0)
  413. {
  414. g.DrawLine(pen,
  415. this.LogicalToDevice(6 + (13 - h) / 2), Offset + i,
  416. this.LogicalToDevice(6 + (13 - h) / 2 + h - 1), Offset + i);
  417. }
  418. i += dx;
  419. i1++;
  420. }
  421. }
  422. private void DrawGuides(Graphics g, BandBase band)
  423. {
  424. FloatCollection guides = band.Guides;
  425. if (guides == null)
  426. return;
  427. g.SmoothingMode = SmoothingMode.HighQuality;
  428. int _4 = this.LogicalToDevice(4);
  429. int _6 = this.LogicalToDevice(6);
  430. int _8 = this.LogicalToDevice(8);
  431. int _32 = this.LogicalToDevice(32);
  432. if (band == activeBand && guides.Count > activeGuide && activeGuide != -1)
  433. {
  434. toolTip.Show(Converter.ToString((Workspace.Page.TopMargin * Units.Millimeters + (band.Top + guides[activeGuide])) / ReportWorkspace.Grid.SnapSize * 10 / 4, typeof(PaperConverter))
  435. + " | "
  436. + Converter.ToString((Workspace.Page.PaperHeight * Units.Millimeters - Workspace.Page.TopMargin * Units.Millimeters - (band.Top + guides[activeGuide])) / ReportWorkspace.Grid.SnapSize * 10 / 4, typeof(PaperConverter)),
  437. this, _32, (int)Math.Round(Offset + (band.Top + guides[activeGuide]) * Designer.ZoomDpi + 10)
  438. );
  439. }
  440. if (activeGuide == -1)
  441. toolTip.Hide(this);
  442. int x = this.LogicalToDevice(16);
  443. for (int i = 0; i < guides.Count; i++)
  444. {
  445. int y = (int)Math.Round(Offset + (band.Top + guides[i]) * Designer.ZoomDpi - _4);
  446. g.FillPolygon(band == activeBand && i == activeGuide ? SystemBrushes.Highlight : Brushes.Black, new Point[]
  447. {
  448. new Point(x, y), new Point(x + _6, y + _4), new Point(x, y + _8)
  449. });
  450. }
  451. }
  452. private BandCollection GetBands()
  453. {
  454. BandCollection bands = new BandCollection();
  455. ObjectCollection objects = PageDesigner.Page.AllObjects;
  456. foreach (Base c in objects)
  457. {
  458. if (c is BandBase)
  459. bands.Add(c as BandBase);
  460. }
  461. return bands;
  462. }
  463. private BandBase BandAt(float y)
  464. {
  465. BandCollection bands = GetBands();
  466. foreach (BandBase b in bands)
  467. {
  468. if (y >= b.Top && y <= b.Bottom + (ReportWorkspace.ClassicView ? BandBase.HeaderSize : 4))
  469. return b;
  470. }
  471. return null;
  472. }
  473. private void MoveGuide(float ky)
  474. {
  475. Workspace.Guides.MoveHGuide(activeBand, activeGuide, ky);
  476. float f = activeBand.Guides[activeGuide];
  477. f += ky;
  478. activeBand.Guides[activeGuide] = Converter.DecreasePrecision(f, 2);
  479. Workspace.Refresh();
  480. Refresh();
  481. }
  482. private void ResizeBand(float ky)
  483. {
  484. activeBand.Height += ky;
  485. activeBand.FixHeight();
  486. Workspace.UpdateBands();
  487. }
  488. private void FixGuide(bool remove)
  489. {
  490. float f = activeBand.Guides[activeGuide];
  491. if (remove || f < 0 || f > activeBand.Height)
  492. activeBand.Guides.RemoveAt(activeGuide);
  493. activeGuide = -1;
  494. Refresh();
  495. }
  496. protected override void OnPaint(PaintEventArgs e)
  497. {
  498. if (Workspace.Locked)
  499. return;
  500. Graphics g = e.Graphics;
  501. // highlight bands list
  502. Hashtable bandsToHighlight = new Hashtable();
  503. if (ReportWorkspace.EnableBacklight)
  504. {
  505. foreach (Base obj in Designer.SelectedObjects)
  506. {
  507. BandBase band = null;
  508. if (obj is BandBase)
  509. band = obj as BandBase;
  510. else if (obj is ReportComponentBase)
  511. band = (obj as ReportComponentBase).Band;
  512. if (band != null)
  513. bandsToHighlight[band] = 1;
  514. }
  515. }
  516. float scale = Designer.ZoomDpi;
  517. BandCollection bands = GetBands();
  518. foreach (BandBase b in bands)
  519. {
  520. Brush brush = bandsToHighlight.ContainsKey(b) ? Brushes.Gainsboro : SystemBrushes.Window;
  521. g.FillRectangle(brush, new RectangleF(
  522. this.LogicalToDevice(5), Offset + b.Top * scale,
  523. Width - this.LogicalToDevice(10), b.Height * scale + 1));
  524. DrawRuler(g, b.Top * scale, b.Height * scale);
  525. DrawGuides(g, b);
  526. if (ReportWorkspace.ClassicView)
  527. {
  528. RectangleF fillRect = new RectangleF(
  529. this.LogicalToDevice(5), Offset + (b.Top - (BandBase.HeaderSize - 1)) * scale,
  530. Width - this.LogicalToDevice(10), (BandBase.HeaderSize - 1) * scale);
  531. if (b.Top == BandBase.HeaderSize)
  532. {
  533. fillRect.Y = 0;
  534. fillRect.Height += scale;
  535. }
  536. b.DrawBandHeader(g, fillRect, true);
  537. if (b.Top > BandBase.HeaderSize)
  538. {
  539. // draw splitter lines
  540. float lineY = fillRect.Top + fillRect.Height / 2 - this.LogicalToDevice(2);
  541. for (int i = 0; i < 6; i += 2)
  542. {
  543. g.DrawLine(SystemPens.ControlDarkDark,
  544. this.LogicalToDevice(9), lineY + this.LogicalToDevice(i),
  545. Width - this.LogicalToDevice(10), lineY + this.LogicalToDevice(i));
  546. }
  547. }
  548. }
  549. }
  550. }
  551. protected override void OnMouseDown(MouseEventArgs e)
  552. {
  553. base.OnMouseDown(e);
  554. if (Workspace.Locked)
  555. return;
  556. float scale = Designer.ZoomDpi;
  557. lastMousePoint = new PointF(e.X / scale, e.Y / scale);
  558. mouseDown = true;
  559. mouseMoved = false;
  560. if (activeBand != null && activeGuide != -1)
  561. Workspace.Guides.BeforeMoveHGuide(activeBand, activeGuide);
  562. saveAutoGuides = ReportWorkspace.AutoGuides;
  563. ReportWorkspace.AutoGuides = false;
  564. }
  565. protected override void OnMouseMove(MouseEventArgs e)
  566. {
  567. base.OnMouseMove(e);
  568. if (Workspace.Locked)
  569. return;
  570. float scale = Designer.ZoomDpi;
  571. if (e.Button == MouseButtons.None)
  572. {
  573. // find band
  574. float y = (e.Y - Offset) / scale;
  575. Cursor = Cursors.Default;
  576. resizing = false;
  577. activeGuide = -1;
  578. activeBand = BandAt(y);
  579. if (activeBand != null)
  580. {
  581. // check band resize
  582. if (y > activeBand.Bottom - 1 &&
  583. y < activeBand.Bottom + (ReportWorkspace.ClassicView ? BandBase.HeaderSize : 4))
  584. {
  585. resizing = true;
  586. Cursor = Cursors.HSplit;
  587. }
  588. else
  589. {
  590. // check guides
  591. FloatCollection guides = activeBand.Guides;
  592. if (guides != null)
  593. {
  594. for (int i = 0; i < guides.Count; i++)
  595. {
  596. if (y > activeBand.Top + guides[i] - 5 &&
  597. y < activeBand.Top + guides[i] + 5)
  598. {
  599. activeGuide = i;
  600. break;
  601. }
  602. }
  603. }
  604. }
  605. }
  606. Refresh();
  607. }
  608. else if (e.Button == MouseButtons.Left)
  609. {
  610. float kx = e.X / scale - lastMousePoint.X;
  611. float ky = e.Y / scale - lastMousePoint.Y;
  612. if (!CheckGridStep(ref kx, ref ky))
  613. return;
  614. if (activeBand != null)
  615. {
  616. if (resizing)
  617. {
  618. mouseMoved = true;
  619. ResizeBand(ky);
  620. }
  621. else if (activeGuide != -1)
  622. {
  623. mouseMoved = true;
  624. MoveGuide(ky);
  625. }
  626. }
  627. lastMousePoint.X += kx;
  628. lastMousePoint.Y += ky;
  629. }
  630. }
  631. protected override void OnMouseUp(MouseEventArgs e)
  632. {
  633. base.OnMouseUp(e);
  634. if (Workspace.Locked)
  635. return;
  636. int _5 = this.LogicalToDevice(5);
  637. int _20 = this.LogicalToDevice(20);
  638. ReportWorkspace.AutoGuides = saveAutoGuides;
  639. mouseDown = false;
  640. if (mouseMoved)
  641. {
  642. if (resizing)
  643. activeBand.FixHeight();
  644. else
  645. FixGuide(e.X < -_5 || e.X > Width + _5);
  646. Workspace.Designer.SetModified(null, resizing ? "ResizeBand" : "MoveGuide");
  647. }
  648. else
  649. {
  650. // create new guide
  651. if (e.X > _5 && e.X < _20)
  652. {
  653. float y = (e.Y - Offset) / Designer.ZoomDpi;
  654. BandBase band = BandAt(y);
  655. if (band != null)
  656. {
  657. y = y - band.Top;
  658. if (ReportWorkspace.SnapToGrid)
  659. y = (int)(y / ReportWorkspace.Grid.SnapSize) * ReportWorkspace.Grid.SnapSize;
  660. if (band.Guides == null)
  661. band.Guides = new FloatCollection();
  662. band.Guides.Add(y);
  663. Workspace.Designer.SetModified(null, "AddGuide");
  664. }
  665. }
  666. }
  667. }
  668. protected override void OnMouseLeave(EventArgs e)
  669. {
  670. base.OnMouseLeave(e);
  671. if (Workspace.Locked)
  672. return;
  673. if (!mouseDown && activeGuide != -1)
  674. {
  675. activeGuide = -1;
  676. Refresh();
  677. }
  678. }
  679. public VertRuler(ReportPageDesigner pd) : base(pd)
  680. {
  681. activeGuide = -1;
  682. }
  683. }
  684. #if !MONO
  685. /// <summary>
  686. /// Represent ruler with guides for forms of editors
  687. /// </summary>
  688. public class RulerWithGuides : EditRuler
  689. {
  690. private bool mouseDown = false;
  691. private Pen pen;
  692. private List<RulerElement> rulerElements;
  693. private RulerElement activElement;
  694. private int countTabPos;
  695. private bool leftIndentIsActive = false;
  696. private bool rightIndentIsActive = false;
  697. #region Properties
  698. /// <summary>
  699. /// Get or set left indent position
  700. /// </summary>
  701. public int LeftIndent
  702. {
  703. get
  704. {
  705. return leftIndent.Indent;
  706. }
  707. set
  708. {
  709. leftIndent.Indent = value;
  710. Invalidate();
  711. }
  712. }
  713. /// <summary>
  714. /// Get or set right indent position
  715. /// </summary>
  716. public int RightIndent
  717. {
  718. get
  719. {
  720. return rightIndent.Indent;
  721. }
  722. set
  723. {
  724. rightIndent.Indent = value;
  725. Invalidate();
  726. }
  727. }
  728. /// <summary>
  729. /// Gets or sets tab positiions
  730. /// </summary>
  731. public int[] TabPositions
  732. {
  733. get
  734. {
  735. List<int> result = new List<int>();
  736. foreach (var elem in rulerElements)
  737. {
  738. if (elem is TabPosition)
  739. {
  740. result.Add(elem.Bounds.X + 4);
  741. }
  742. }
  743. result.Sort();
  744. return result.ToArray();
  745. }
  746. set
  747. {
  748. for (int i = 0; i < rulerElements.Count; i++)
  749. {
  750. if (rulerElements[i] is TabPosition)
  751. {
  752. rulerElements.Remove(rulerElements[i]);
  753. i--;
  754. }
  755. }
  756. for (int i = 0; i < value.Length; i++)
  757. {
  758. rulerElements.Add(new TabPosition(value[i]));
  759. }
  760. Invalidate();
  761. }
  762. }
  763. #endregion
  764. #region Protected method
  765. /// <inheritdoc/>
  766. protected override void OnDoubleClick(EventArgs e)
  767. {
  768. base.OnDoubleClick(e);
  769. MouseEventArgs me = e as MouseEventArgs;
  770. if (me.X > RulerStart && me.X < RulerWidth && me.Button == MouseButtons.Left && !TabPosExist(me.X) &&
  771. countTabPos + 1 <= 32 && !leftIndentIsActive && !rightIndentIsActive && activElement == null)
  772. {
  773. rulerElements.Add(new TabPosition(me.X));
  774. countTabPos++;
  775. OnChange(this);
  776. }
  777. }
  778. /// <inheritdoc/>
  779. protected override Rectangle GetIndentHitRect(RulerIndent Indent)
  780. {
  781. Rectangle result = Rectangle.Empty;
  782. if (Vertical)
  783. {
  784. //if (Indent.Orientation == IndentOrientation.Near)
  785. // result = new Rectangle(cRulerTop, RulerStart + Indent.Indent - EditConsts.DefaultRulerHitWidth, cRulerHeight, EditConsts.DefaultRulerHitWidth * 2);
  786. //else
  787. // result = new Rectangle(cRulerTop, PageStart + PageWidth - EditConsts.DefaultRulerHitWidth, cRulerHeight, EditConsts.DefaultRulerHitWidth * 2);
  788. }
  789. else
  790. {
  791. if (Indent.Orientation == IndentOrientation.Near)
  792. result = new Rectangle(RulerStart + Indent.Indent - EditConsts.DefaultRulerHitWidth, cRulerTop, EditConsts.DefaultRulerHitWidth * 2, cRulerHeight);
  793. else
  794. result = new Rectangle(RulerStart + RulerWidth - EditConsts.DefaultRulerHitWidth - Indent.Indent, cRulerTop, EditConsts.DefaultRulerHitWidth * 2, cRulerHeight);
  795. }
  796. return result;
  797. }
  798. /// <inheritdoc/>
  799. protected override Rectangle GetIndentRect(RulerIndent indent)
  800. {
  801. Rectangle result = Rectangle.Empty;
  802. if (Vertical)
  803. {
  804. //if (indent.Orientation == IndentOrientation.Near)
  805. // result = new Rectangle(cRulerTop, RulerStart, cRulerHeight, indent.Indent);
  806. //else
  807. // result = new Rectangle(cRulerTop, PageWidth + PageStart, cRulerHeight, indent.Indent);
  808. }
  809. else
  810. {
  811. if (indent.Orientation == IndentOrientation.Near)
  812. result = new Rectangle(RulerStart, cRulerTop, indent.Indent, cRulerHeight);
  813. else
  814. result = new Rectangle(RulerWidth + RulerStart - indent.Indent, cRulerTop, indent.Indent, cRulerHeight);
  815. }
  816. return result;
  817. }
  818. /// <inheritdoc/>
  819. protected override void OnPaint(PaintEventArgs pe)
  820. {
  821. base.OnPaint(pe);
  822. foreach (var elem in rulerElements)
  823. {
  824. elem.Draw(pe.Graphics);
  825. }
  826. }
  827. /// <inheritdoc/>
  828. protected override void OnMouseDown(MouseEventArgs e)
  829. {
  830. base.OnMouseDown(e);
  831. mouseDown = true;
  832. if (RulerWidth - RightIndent + RulerStart + 2 >= e.X && RulerWidth - RightIndent + RulerStart - 4 <= e.X && e.Button != MouseButtons.Right)
  833. rightIndentIsActive = true;
  834. else if (LeftIndent + RulerStart - 4 <= e.X && LeftIndent + RulerStart + 2 >= e.X && e.Button != MouseButtons.Right)
  835. leftIndentIsActive = true;
  836. else
  837. foreach (var elem in rulerElements)
  838. {
  839. if (elem.Bounds.Contains(e.Location))
  840. {
  841. if (e.Button == MouseButtons.Right && elem is TabPosition)
  842. {
  843. rulerElements.Remove(elem);
  844. countTabPos--;
  845. }
  846. else
  847. {
  848. activElement = elem;
  849. activElement.IsActive = true;
  850. if (e.X > RulerWidth + RulerStart - RightIndent)
  851. activElement.Move(new Point(RulerWidth + RulerStart - RightIndent, 0));
  852. else if (e.X < RulerStart + LeftIndent)
  853. activElement.Move(new Point(RulerStart + LeftIndent, 0));
  854. }
  855. break;
  856. }
  857. }
  858. OnChange(this);
  859. }
  860. /// <inheritdoc/>
  861. protected override void OnMouseMove(MouseEventArgs e)
  862. {
  863. int oldLeftIndent = LeftIndent;
  864. base.OnMouseMove(e);
  865. if (mouseDown && activElement != null && e.X < RulerWidth + RulerStart - RightIndent && e.X > RulerStart + LeftIndent)
  866. {
  867. activElement.Move(e.Location);
  868. OnChange(this);
  869. }
  870. else if (mouseDown && leftIndentIsActive)
  871. {
  872. int dx = LeftIndent - oldLeftIndent;
  873. //if (dx != 0)
  874. dx += 4;
  875. foreach (var elem in rulerElements)
  876. {
  877. elem.Move(new Point(elem.Bounds.X + dx, 0));
  878. }
  879. }
  880. }
  881. /// <inheritdoc/>
  882. protected override void OnChange(object sender)
  883. {
  884. base.OnChange(sender);
  885. Invalidate();
  886. }
  887. /// <inheritdoc/>
  888. protected override void OnMouseCaptureChanged(EventArgs e)
  889. {
  890. base.OnMouseCaptureChanged(e);
  891. mouseDown = false;
  892. if (activElement != null)
  893. activElement.IsActive = false;
  894. activElement = null;
  895. leftIndentIsActive = false;
  896. rightIndentIsActive = false;
  897. OnChange(this);
  898. }
  899. /// <inheritdoc/>
  900. protected override void OnMouseUp(MouseEventArgs e)
  901. {
  902. base.OnMouseUp(e);
  903. mouseDown = false;
  904. if (activElement != null)
  905. activElement.IsActive = false;
  906. activElement = null;
  907. leftIndentIsActive = false;
  908. rightIndentIsActive = false;
  909. OnChange(this);
  910. }
  911. /// <inheritdoc/>
  912. protected override void InitLayout()
  913. {
  914. base.InitLayout();
  915. pen = new Pen(Color.Black, 1);
  916. pen.DashStyle = DashStyle.Dash;
  917. pen.DashPattern = new float[] { 4, 4 };
  918. rulerElements = new List<RulerElement>();
  919. }
  920. /// <inheritdoc/>
  921. protected override void OnHandleDestroyed(EventArgs e)
  922. {
  923. pen.Dispose();
  924. base.OnHandleDestroyed(e);
  925. }
  926. #endregion
  927. private bool TabPosExist(int x)
  928. {
  929. foreach (var elem in rulerElements)
  930. {
  931. if (elem.Bounds.Contains(x, elem.Bounds.Y) && elem is TabPosition)
  932. {
  933. return true;
  934. }
  935. }
  936. return false;
  937. }
  938. /// <summary>
  939. /// Method for drawing guides on element of form.
  940. /// </summary>
  941. /// <param name="sender"></param>
  942. /// <param name="e"></param>
  943. public void DrawGuides(object sender, PaintEventArgs e)
  944. {
  945. if (mouseDown)
  946. {
  947. if (activElement != null)
  948. e.Graphics.DrawLine(pen, new Point(activElement.Bounds.X + 4, e.ClipRectangle.Top), new Point(activElement.Bounds.X + 4, e.ClipRectangle.Bottom));
  949. else if (leftIndentIsActive)
  950. e.Graphics.DrawLine(pen, new Point(LeftIndent + RulerStart, e.ClipRectangle.Top), new Point(LeftIndent + RulerStart, e.ClipRectangle.Bottom));
  951. else if (rightIndentIsActive)
  952. e.Graphics.DrawLine(pen, new Point(RulerWidth - RightIndent + RulerStart + 2, e.ClipRectangle.Top), new Point(RulerWidth - RightIndent + RulerStart + 2, e.ClipRectangle.Bottom));
  953. }
  954. }
  955. /// <summary>
  956. /// Base class for elements of RulerWithGuides
  957. /// </summary>
  958. public class RulerElement
  959. {
  960. private bool isActive;
  961. private Rectangle bounds;
  962. /// <summary>
  963. /// Get or set bounds of object
  964. /// </summary>
  965. public Rectangle Bounds
  966. {
  967. get { return bounds; }
  968. set { bounds = value; }
  969. }
  970. /// <summary>
  971. /// Get or set state of object
  972. /// </summary>
  973. public bool IsActive
  974. {
  975. get { return isActive; }
  976. set { isActive = value; }
  977. }
  978. /// <summary>
  979. /// Draw element on graphics
  980. /// </summary>
  981. /// <param name="g"></param>
  982. public virtual void Draw(Graphics g) { }
  983. /// <summary>
  984. /// Method for moving object by means of chenging bounds
  985. /// </summary>
  986. /// <param name="location"></param>
  987. public virtual void Move(Point location) { }
  988. }
  989. /// <summary>
  990. /// Element of RulerWithGuides presenting position of tabs
  991. /// </summary>
  992. public class TabPosition : RulerElement
  993. {
  994. /// <summary>
  995. /// Constructor of class TabPosition
  996. /// </summary>
  997. /// <param name="x"></param>
  998. public TabPosition(int x)
  999. {
  1000. IsActive = false;
  1001. Bounds = new Rectangle(x - 4, 16, 14, 14);
  1002. }
  1003. /// <inheritdoc/>
  1004. public override void Draw(Graphics g)
  1005. {
  1006. base.Draw(g);
  1007. if (IsActive)
  1008. g.DrawImage(Res.GetImage(174, 96), Bounds);
  1009. else
  1010. g.DrawImage(Res.GetImage(74, 96), Bounds);
  1011. }
  1012. /// <inheritdoc/>
  1013. public override void Move(Point location)
  1014. {
  1015. base.Move(location);
  1016. Bounds = new Rectangle(location.X - 4, 16, 14, 14);
  1017. }
  1018. }
  1019. }
  1020. #endif
  1021. }