AnnotationCollection.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. //
  5. // Purpose: Collection of annotation objects.
  6. //
  7. using System;
  8. using System.Windows.Forms;
  9. using System.Diagnostics.CodeAnalysis;
  10. using System.Drawing;
  11. namespace FastReport.DataVisualization.Charting
  12. {
  13. /// <summary>
  14. /// <b>AnnotationCollection</b> is a collection that stores chart annotation objects.
  15. /// <seealso cref="Charting.Chart.Annotations"/>
  16. /// </summary>
  17. /// <remarks>
  18. /// All chart annotations are stored in this collection. It is exposed as
  19. /// a <see cref="Charting.Chart.Annotations"/> property of the chart. It is also used to
  20. /// store annotations inside the <see cref="AnnotationGroup"/> class.
  21. /// <para>
  22. /// This class includes methods for adding, inserting, iterating and removing annotations.
  23. /// </para>
  24. /// </remarks>
  25. [
  26. SRDescription("DescriptionAttributeAnnotations3"),
  27. ]
  28. public class AnnotationCollection : ChartNamedElementCollection<Annotation>
  29. {
  30. #region Fields
  31. /// <summary>
  32. /// Group this collection belongs too
  33. /// </summary>
  34. internal AnnotationGroup AnnotationGroup { get; set; }
  35. // Annotation object that was last clicked on
  36. internal Annotation lastClickedAnnotation = null;
  37. // Start point of annotation moving or resizing
  38. private PointF _movingResizingStartPoint = PointF.Empty;
  39. // Current resizing mode
  40. private ResizingMode _resizingMode = ResizingMode.None;
  41. // Annotation object which is currently placed on the chart
  42. internal Annotation placingAnnotation = null;
  43. #endregion
  44. #region Construction and Initialization
  45. /// <summary>
  46. /// Initializes a new instance of the <see cref="AnnotationCollection"/> class.
  47. /// </summary>
  48. /// <param name="parent">The parent chart element.</param>
  49. internal AnnotationCollection(IChartElement parent) : base(parent)
  50. {
  51. }
  52. #endregion
  53. #region Items Inserting and Removing Notification methods
  54. /// <summary>
  55. /// Initializes the specified item.
  56. /// </summary>
  57. /// <param name="item">The item.</param>
  58. internal override void Initialize(Annotation item)
  59. {
  60. if (item != null)
  61. {
  62. TextAnnotation textAnnotation = item as TextAnnotation;
  63. if (textAnnotation != null && string.IsNullOrEmpty(textAnnotation.Text) && Chart != null && Chart.IsDesignMode())
  64. {
  65. textAnnotation.Text = item.Name;
  66. }
  67. //If the collection belongs to annotation group we need to pass a ref to this group to all the child annotations
  68. if (this.AnnotationGroup != null)
  69. {
  70. item.annotationGroup = this.AnnotationGroup;
  71. }
  72. item.ResetCurrentRelativePosition();
  73. }
  74. base.Initialize(item);
  75. }
  76. /// <summary>
  77. /// Deinitializes the specified item.
  78. /// </summary>
  79. /// <param name="item">The item.</param>
  80. internal override void Deinitialize(Annotation item)
  81. {
  82. if (item != null)
  83. {
  84. item.annotationGroup = null;
  85. item.ResetCurrentRelativePosition();
  86. }
  87. base.Deinitialize(item);
  88. }
  89. /// <summary>
  90. /// Finds an annotation in the collection by name.
  91. /// </summary>
  92. /// <param name="name">
  93. /// Name of the annotation to find.
  94. /// </param>
  95. /// <returns>
  96. /// <see cref="Annotation"/> object, or null (or nothing) if it does not exist.
  97. /// </returns>
  98. public override Annotation FindByName(string name)
  99. {
  100. foreach(Annotation annotation in this)
  101. {
  102. // Compare annotation name
  103. if(annotation.Name == name)
  104. {
  105. return annotation;
  106. }
  107. // Check if annotation is a group
  108. AnnotationGroup annotationGroup = annotation as AnnotationGroup;
  109. if(annotationGroup != null)
  110. {
  111. Annotation result = annotationGroup.Annotations.FindByName(name);
  112. if(result != null)
  113. {
  114. return result;
  115. }
  116. }
  117. }
  118. return null;
  119. }
  120. #endregion
  121. #region Painting
  122. /// <summary>
  123. /// Paints all annotation objects in the collection.
  124. /// </summary>
  125. /// <param name="chartGraph">Chart graphics used for painting.</param>
  126. /// <param name="drawAnnotationOnly">Indicates that only annotation objects are redrawn.</param>
  127. [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification="This parameter is used when compiling for the WinForms version of Chart")]
  128. internal void Paint(ChartGraphics chartGraph, bool drawAnnotationOnly)
  129. {
  130. ChartPicture chartPicture = this.Chart.chartPicture;
  131. // Restore previous background using double buffered bitmap
  132. if(!chartPicture.isSelectionMode &&
  133. this.Count > 0 /*&&
  134. !this.Chart.chartPicture.isPrinting*/)
  135. {
  136. chartPicture.backgroundRestored = true;
  137. Rectangle chartPosition = new Rectangle(0, 0, chartPicture.Width, chartPicture.Height);
  138. if(chartPicture.nonTopLevelChartBuffer == null || !drawAnnotationOnly)
  139. {
  140. // Dispose previous bitmap
  141. if(chartPicture.nonTopLevelChartBuffer != null)
  142. {
  143. chartPicture.nonTopLevelChartBuffer.Dispose();
  144. chartPicture.nonTopLevelChartBuffer = null;
  145. }
  146. // Copy chart area plotting rectangle from the chart's dubble buffer image into area dubble buffer image
  147. if (this.Chart.paintBufferBitmap != null &&
  148. this.Chart.paintBufferBitmap.Size.Width >= chartPosition.Size.Width &&
  149. this.Chart.paintBufferBitmap.Size.Height >= chartPosition.Size.Height)
  150. {
  151. chartPicture.nonTopLevelChartBuffer = this.Chart.paintBufferBitmap.Clone(
  152. chartPosition, this.Chart.paintBufferBitmap.PixelFormat);
  153. }
  154. }
  155. else if(drawAnnotationOnly && chartPicture.nonTopLevelChartBuffer != null)
  156. {
  157. // Restore previous background
  158. this.Chart.paintBufferBitmapGraphics.DrawImageUnscaled(
  159. chartPicture.nonTopLevelChartBuffer,
  160. chartPosition);
  161. }
  162. }
  163. // Draw all annotation objects
  164. foreach(Annotation annotation in this)
  165. {
  166. // Reset calculated relative position
  167. annotation.ResetCurrentRelativePosition();
  168. if(annotation.IsVisible())
  169. {
  170. bool resetClip = false;
  171. // Check if anchor point assosiated with plot area is inside the scaleView
  172. if(annotation.IsAnchorVisible())
  173. {
  174. // Set annotation object clipping
  175. if(annotation.ClipToChartArea.Length > 0 &&
  176. annotation.ClipToChartArea != Constants.NotSetValue &&
  177. Chart != null)
  178. {
  179. int areaIndex = Chart.ChartAreas.IndexOf(annotation.ClipToChartArea);
  180. if( areaIndex >= 0 )
  181. {
  182. // Get chart area object
  183. ChartArea chartArea = Chart.ChartAreas[areaIndex];
  184. chartGraph.SetClip(chartArea.PlotAreaPosition.ToRectangleF());
  185. resetClip = true;
  186. }
  187. }
  188. // Start Svg Selection mode
  189. string url = String.Empty;
  190. chartGraph.StartHotRegion(
  191. annotation.ReplaceKeywords(url),
  192. annotation.ReplaceKeywords(annotation.ToolTip) );
  193. // Draw annotation object
  194. annotation.Paint(Chart, chartGraph);
  195. // End Svg Selection mode
  196. chartGraph.EndHotRegion( );
  197. // Reset clipping region
  198. if(resetClip)
  199. {
  200. chartGraph.ResetClip();
  201. }
  202. }
  203. }
  204. }
  205. }
  206. #endregion
  207. #region Mouse Events Handlers
  208. /// <summary>
  209. /// Mouse was double clicked.
  210. /// </summary>
  211. internal void OnDoubleClick()
  212. {
  213. if(lastClickedAnnotation != null &&
  214. lastClickedAnnotation.AllowTextEditing)
  215. {
  216. TextAnnotation textAnnotation = lastClickedAnnotation as TextAnnotation;
  217. if(textAnnotation == null)
  218. {
  219. AnnotationGroup group = lastClickedAnnotation as AnnotationGroup;
  220. if (group != null)
  221. {
  222. // Try to edit text annotation in the group
  223. foreach (Annotation annot in group.Annotations)
  224. {
  225. TextAnnotation groupAnnot = annot as TextAnnotation;
  226. if (groupAnnot != null &&
  227. groupAnnot.AllowTextEditing)
  228. {
  229. // Get annotation position in relative coordinates
  230. PointF firstPoint = PointF.Empty;
  231. PointF anchorPoint = PointF.Empty;
  232. SizeF size = SizeF.Empty;
  233. groupAnnot.GetRelativePosition(out firstPoint, out size, out anchorPoint);
  234. RectangleF textPosition = new RectangleF(firstPoint, size);
  235. // Check if last clicked coordinate is inside this text annotation
  236. if (groupAnnot.GetGraphics() != null &&
  237. textPosition.Contains(groupAnnot.GetGraphics().GetRelativePoint(this._movingResizingStartPoint)))
  238. {
  239. textAnnotation = groupAnnot;
  240. lastClickedAnnotation = textAnnotation;
  241. break;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. if(textAnnotation != null)
  248. {
  249. // Start annotation text editing
  250. textAnnotation.BeginTextEditing();
  251. }
  252. }
  253. }
  254. /// <summary>
  255. /// Checks if specified point is contained by any of the selection handles.
  256. /// </summary>
  257. /// <param name="point">Point which is tested in pixel coordinates.</param>
  258. /// <param name="resizingMode">Handle containing the point or None.</param>
  259. /// <returns>Annotation that contains the point or Null.</returns>
  260. internal Annotation HitTestSelectionHandles(PointF point, ref ResizingMode resizingMode)
  261. {
  262. Annotation annotation = null;
  263. if( Common != null &&
  264. Common.graph != null)
  265. {
  266. PointF pointRel = Common.graph.GetRelativePoint(point);
  267. foreach(Annotation annot in this)
  268. {
  269. // Reset selcted path point
  270. annot.currentPathPointIndex = -1;
  271. // Check if annotation is selected
  272. if(annot.IsSelected)
  273. {
  274. if(annot.selectionRects != null)
  275. {
  276. for(int index = 0; index < annot.selectionRects.Length; index++)
  277. {
  278. if(!annot.selectionRects[index].IsEmpty &&
  279. annot.selectionRects[index].Contains(pointRel))
  280. {
  281. annotation = annot;
  282. if(index > (int)ResizingMode.AnchorHandle)
  283. {
  284. resizingMode = ResizingMode.MovingPathPoints;
  285. annot.currentPathPointIndex = index - 9;
  286. }
  287. else
  288. {
  289. resizingMode = (ResizingMode)index;
  290. }
  291. }
  292. }
  293. }
  294. }
  295. }
  296. }
  297. return annotation;
  298. }
  299. /// <summary>
  300. /// Mouse button pressed in the control.
  301. /// </summary>
  302. /// <param name="e">Event arguments.</param>
  303. /// <param name="isHandled">Returns true if event is handled and no further processing required.</param>
  304. internal void OnMouseDown(MouseEventArgs e, ref bool isHandled)
  305. {
  306. // Reset last clicked annotation object and stop text editing
  307. if(lastClickedAnnotation != null)
  308. {
  309. TextAnnotation textAnnotation = lastClickedAnnotation as TextAnnotation;
  310. if(textAnnotation != null)
  311. {
  312. // Stop annotation text editing
  313. textAnnotation.StopTextEditing();
  314. }
  315. lastClickedAnnotation = null;
  316. }
  317. // Check if in annotation placement mode
  318. if( this.placingAnnotation != null)
  319. {
  320. // Process mouse down
  321. this.placingAnnotation.PlacementMouseDown(new PointF(e.X, e.Y), e.Button);
  322. // Set handled flag
  323. isHandled = true;
  324. return;
  325. }
  326. // Process only left mouse buttons
  327. if(e.Button == MouseButtons.Left)
  328. {
  329. bool updateRequired = false;
  330. this._resizingMode = ResizingMode.None;
  331. // Check if mouse buton was pressed in any selection handles areas
  332. Annotation annotation =
  333. HitTestSelectionHandles(new PointF(e.X, e.Y), ref this._resizingMode);
  334. // Check if mouse button was pressed over one of the annotation objects
  335. if(annotation == null && this.Count > 0)
  336. {
  337. HitTestResult result = this.Chart.HitTest(e.X, e.Y, ChartElementType.Annotation);
  338. if(result != null && result.ChartElementType == ChartElementType.Annotation)
  339. {
  340. annotation = (Annotation)result.Object;
  341. }
  342. }
  343. // Unselect all annotations if mouse clicked outside any annotations
  344. if(annotation == null || !annotation.IsSelected)
  345. {
  346. if((Control.ModifierKeys & Keys.Control) != Keys.Control &&
  347. (Control.ModifierKeys & Keys.Shift) != Keys.Shift)
  348. {
  349. foreach (Annotation annot in this.Chart.Annotations)
  350. {
  351. if(annot != annotation && annot.IsSelected)
  352. {
  353. annot.IsSelected = false;
  354. updateRequired = true;
  355. // Call selection changed notification
  356. if (this.Chart != null)
  357. {
  358. this.Chart.OnAnnotationSelectionChanged(annot);
  359. }
  360. }
  361. }
  362. }
  363. }
  364. // Process mouse action in the annotation object
  365. if(annotation != null)
  366. {
  367. // Mouse down event handled
  368. isHandled = true;
  369. // Select/Unselect annotation
  370. Annotation selectableAnnotation = annotation;
  371. if(annotation.AnnotationGroup != null)
  372. {
  373. // Select annotation group when click on any child annotations
  374. selectableAnnotation = annotation.AnnotationGroup;
  375. }
  376. if(!selectableAnnotation.IsSelected && selectableAnnotation.AllowSelecting)
  377. {
  378. selectableAnnotation.IsSelected = true;
  379. updateRequired = true;
  380. // Call selection changed notification
  381. if (this.Chart != null)
  382. {
  383. this.Chart.OnAnnotationSelectionChanged(selectableAnnotation);
  384. }
  385. }
  386. else if((Control.ModifierKeys & Keys.Control) == Keys.Control ||
  387. (Control.ModifierKeys & Keys.Shift) == Keys.Shift)
  388. {
  389. selectableAnnotation.IsSelected = false;
  390. updateRequired = true;
  391. // Call selection changed notification
  392. if (this.Chart != null)
  393. {
  394. this.Chart.OnAnnotationSelectionChanged(selectableAnnotation);
  395. }
  396. }
  397. // Remember last clicked and selected annotation
  398. lastClickedAnnotation = annotation;
  399. // Rember mouse position
  400. this._movingResizingStartPoint = new PointF(e.X, e.Y);
  401. // Start moving, repositioning or resizing of annotation
  402. if(annotation.IsSelected)
  403. {
  404. // Check if one of selection handles was clicked on
  405. this._resizingMode = annotation.GetSelectionHandle(this._movingResizingStartPoint);
  406. if(!annotation.AllowResizing &&
  407. this._resizingMode >= ResizingMode.TopLeftHandle &&
  408. this._resizingMode <= ResizingMode.LeftHandle)
  409. {
  410. this._resizingMode = ResizingMode.None;
  411. }
  412. if(!annotation.AllowAnchorMoving &&
  413. this._resizingMode == ResizingMode.AnchorHandle)
  414. {
  415. this._resizingMode = ResizingMode.None;
  416. }
  417. if(this._resizingMode == ResizingMode.None && annotation.AllowMoving)
  418. {
  419. // Annotation moving mode
  420. this._resizingMode = ResizingMode.Moving;
  421. }
  422. }
  423. else
  424. {
  425. if(this._resizingMode == ResizingMode.None && annotation.AllowMoving)
  426. {
  427. // Do not allow moving child annotations inside the group.
  428. // Only the whole group can be selected, resized or repositioned.
  429. if (annotation.AnnotationGroup != null)
  430. {
  431. // Move the group instead
  432. lastClickedAnnotation = annotation.AnnotationGroup;
  433. }
  434. // Annotation moving mode
  435. this._resizingMode = ResizingMode.Moving;
  436. }
  437. }
  438. }
  439. // Update chart
  440. if(updateRequired)
  441. {
  442. // Invalidate and update the chart
  443. this.Chart.Invalidate(true);
  444. this.Chart.UpdateAnnotations();
  445. }
  446. }
  447. }
  448. /// <summary>
  449. /// Mouse button released in the control.
  450. /// </summary>
  451. /// <param name="e">Event arguments.</param>
  452. internal void OnMouseUp(MouseEventArgs e)
  453. {
  454. // Check if in annotation placement mode
  455. if( this.placingAnnotation != null)
  456. {
  457. if(!this.placingAnnotation.PlacementMouseUp(new PointF(e.X, e.Y), e.Button))
  458. {
  459. return;
  460. }
  461. }
  462. if(e.Button == MouseButtons.Left)
  463. {
  464. // Reset moving sizing start point
  465. this._movingResizingStartPoint = PointF.Empty;
  466. this._resizingMode = ResizingMode.None;
  467. }
  468. // Loop through all annotation objects
  469. for(int index = 0; index < this.Count; index++)
  470. {
  471. Annotation annotation = this[index];
  472. // NOTE: Automatic deleting feature was disabled. -AG.
  473. /*
  474. // Delete all annotation objects moved outside clipping region
  475. if( annotation.outsideClipRegion )
  476. {
  477. this.List.RemoveAt(index);
  478. --index;
  479. }
  480. */
  481. // Reset start position/location fields
  482. annotation.startMovePositionRel = RectangleF.Empty;
  483. annotation.startMoveAnchorLocationRel = PointF.Empty;
  484. if(annotation.startMovePathRel != null)
  485. {
  486. annotation.startMovePathRel.Dispose();
  487. annotation.startMovePathRel = null;
  488. }
  489. // Fire position changed event
  490. if( annotation.positionChanged )
  491. {
  492. annotation.positionChanged = false;
  493. if (this.Chart != null)
  494. {
  495. this.Chart.OnAnnotationPositionChanged(annotation);
  496. }
  497. }
  498. }
  499. }
  500. /// <summary>
  501. /// Mouse moved in the control.
  502. /// </summary>
  503. /// <param name="e">Event arguments.</param>
  504. internal void OnMouseMove(MouseEventArgs e)
  505. {
  506. // Check if in annotation placement mode
  507. if(this.placingAnnotation != null)
  508. {
  509. System.Windows.Forms.Cursor newCursor = this.Chart.Cursor;
  510. if(this.placingAnnotation.IsValidPlacementPosition(e.X, e.Y))
  511. {
  512. newCursor = Cursors.Cross;
  513. }
  514. else
  515. {
  516. newCursor = this.Chart.defaultCursor;
  517. }
  518. // Set current chart cursor
  519. if (newCursor != this.Chart.Cursor)
  520. {
  521. System.Windows.Forms.Cursor tmpCursor = this.Chart.defaultCursor;
  522. this.Chart.Cursor = newCursor;
  523. this.Chart.defaultCursor = tmpCursor;
  524. }
  525. this.placingAnnotation.PlacementMouseMove(new PointF(e.X, e.Y));
  526. return;
  527. }
  528. // Check if currently resizing/moving annotation
  529. if(!this._movingResizingStartPoint.IsEmpty &&
  530. this._resizingMode != ResizingMode.None)
  531. {
  532. // Calculate how far the mouse was moved
  533. SizeF moveDistance = new SizeF(
  534. this._movingResizingStartPoint.X - e.X,
  535. this._movingResizingStartPoint.Y - e.Y );
  536. // Update location of all selected annotation objects
  537. foreach(Annotation annot in this)
  538. {
  539. if(annot.IsSelected &&
  540. ( (this._resizingMode == ResizingMode.MovingPathPoints && annot.AllowPathEditing) ||
  541. (this._resizingMode == ResizingMode.Moving && annot.AllowMoving) ||
  542. (this._resizingMode == ResizingMode.AnchorHandle && annot.AllowAnchorMoving) ||
  543. (this._resizingMode >= ResizingMode.TopLeftHandle && this._resizingMode <= ResizingMode.LeftHandle && annot.AllowResizing) ) )
  544. {
  545. annot.AdjustLocationSize(moveDistance, this._resizingMode, true, true);
  546. }
  547. }
  548. // Move last clicked non-selected annotation
  549. if(lastClickedAnnotation != null &&
  550. !lastClickedAnnotation.IsSelected)
  551. {
  552. if(this._resizingMode == ResizingMode.Moving &&
  553. lastClickedAnnotation.AllowMoving)
  554. {
  555. lastClickedAnnotation.AdjustLocationSize(moveDistance, this._resizingMode, true, true);
  556. }
  557. }
  558. // Invalidate and update the chart
  559. this.Chart.Invalidate(true);
  560. this.Chart.UpdateAnnotations();
  561. }
  562. else if(this.Count > 0)
  563. {
  564. // Check if currently placing annotation from the UserInterface
  565. bool process = true;
  566. if(process)
  567. {
  568. // Check if mouse pointer is over the annotation selection handle
  569. ResizingMode currentResizingMode = ResizingMode.None;
  570. Annotation annotation =
  571. HitTestSelectionHandles(new PointF(e.X, e.Y), ref currentResizingMode);
  572. // Check if mouse pointer over the annotation object movable area
  573. if(annotation == null)
  574. {
  575. HitTestResult result = this.Chart.HitTest(e.X, e.Y, ChartElementType.Annotation);
  576. if(result != null && result.ChartElementType == ChartElementType.Annotation)
  577. {
  578. annotation = (Annotation)result.Object;
  579. if(annotation != null)
  580. {
  581. // Check if annotation is in the collection
  582. if(this.Contains(annotation))
  583. {
  584. currentResizingMode = ResizingMode.Moving;
  585. if(annotation.AllowMoving == false)
  586. {
  587. // Movement is not allowed
  588. annotation = null;
  589. currentResizingMode = ResizingMode.None;
  590. }
  591. }
  592. }
  593. }
  594. }
  595. // Set mouse cursor
  596. SetResizingCursor(annotation, currentResizingMode);
  597. }
  598. }
  599. }
  600. /// <summary>
  601. /// Sets mouse cursor shape.
  602. /// </summary>
  603. /// <param name="annotation">Annotation object.</param>
  604. /// <param name="currentResizingMode">Resizing mode.</param>
  605. private void SetResizingCursor(Annotation annotation, ResizingMode currentResizingMode)
  606. {
  607. // Change current cursor
  608. if(this.Chart != null)
  609. {
  610. System.Windows.Forms.Cursor newCursor = this.Chart.Cursor;
  611. if(annotation != null)
  612. {
  613. if(currentResizingMode == ResizingMode.MovingPathPoints &&
  614. annotation.AllowPathEditing)
  615. {
  616. newCursor = Cursors.Cross;
  617. }
  618. if(currentResizingMode == ResizingMode.Moving &&
  619. annotation.AllowMoving)
  620. {
  621. newCursor = Cursors.SizeAll;
  622. }
  623. if(currentResizingMode == ResizingMode.AnchorHandle &&
  624. annotation.AllowAnchorMoving)
  625. {
  626. newCursor = Cursors.Cross;
  627. }
  628. if(currentResizingMode != ResizingMode.Moving &&
  629. annotation.AllowResizing)
  630. {
  631. if(annotation.SelectionPointsStyle == SelectionPointsStyle.TwoPoints)
  632. {
  633. if(currentResizingMode == ResizingMode.TopLeftHandle ||
  634. currentResizingMode == ResizingMode.BottomRightHandle)
  635. {
  636. newCursor = Cursors.Cross;
  637. }
  638. }
  639. else
  640. {
  641. if(currentResizingMode == ResizingMode.TopLeftHandle ||
  642. currentResizingMode == ResizingMode.BottomRightHandle)
  643. {
  644. newCursor = Cursors.SizeNWSE;
  645. }
  646. else if(currentResizingMode == ResizingMode.TopRightHandle ||
  647. currentResizingMode == ResizingMode.BottomLeftHandle)
  648. {
  649. newCursor = Cursors.SizeNESW;
  650. }
  651. else if(currentResizingMode == ResizingMode.TopHandle ||
  652. currentResizingMode == ResizingMode.BottomHandle)
  653. {
  654. newCursor = Cursors.SizeNS;
  655. }
  656. else if(currentResizingMode == ResizingMode.LeftHandle ||
  657. currentResizingMode == ResizingMode.RightHandle)
  658. {
  659. newCursor = Cursors.SizeWE;
  660. }
  661. }
  662. }
  663. }
  664. else
  665. {
  666. newCursor = this.Chart.defaultCursor;
  667. }
  668. // Set current chart cursor
  669. if (newCursor != this.Chart.Cursor)
  670. {
  671. System.Windows.Forms.Cursor tmpCursor = this.Chart.defaultCursor;
  672. this.Chart.Cursor = newCursor;
  673. this.Chart.defaultCursor = tmpCursor;
  674. }
  675. }
  676. }
  677. #endregion
  678. #region Event handlers
  679. internal void ChartAreaNameReferenceChanged(object sender, NameReferenceChangedEventArgs e)
  680. {
  681. // If all the chart areas are removed and then a new one is inserted - Annotations don't get bound to it by default
  682. if (e.OldElement == null)
  683. return;
  684. foreach (Annotation annotation in this)
  685. {
  686. if (annotation.ClipToChartArea == e.OldName)
  687. annotation.ClipToChartArea = e.NewName;
  688. AnnotationGroup group = annotation as AnnotationGroup;
  689. if (group != null)
  690. {
  691. group.Annotations.ChartAreaNameReferenceChanged(sender, e);
  692. }
  693. }
  694. }
  695. #endregion
  696. }
  697. }