/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLineElementGenerator.cs

http://github.com/icsharpcode/ILSpy · C# · 78 lines · 25 code · 8 blank · 45 comment · 2 complexity · 5527a9cde2dd2adcb54213c89a7decb0 MD5 · raw file

  1. // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. namespace ICSharpCode.AvalonEdit.Rendering
  20. {
  21. /// <summary>
  22. /// Abstract base class for generators that produce new visual line elements.
  23. /// </summary>
  24. public abstract class VisualLineElementGenerator
  25. {
  26. /// <summary>
  27. /// Gets the text run construction context.
  28. /// </summary>
  29. protected ITextRunConstructionContext CurrentContext { get; private set; }
  30. /// <summary>
  31. /// Initializes the generator for the <see cref="ITextRunConstructionContext"/>
  32. /// </summary>
  33. public virtual void StartGeneration(ITextRunConstructionContext context)
  34. {
  35. if (context == null)
  36. throw new ArgumentNullException("context");
  37. this.CurrentContext = context;
  38. }
  39. /// <summary>
  40. /// De-initializes the generator.
  41. /// </summary>
  42. public virtual void FinishGeneration()
  43. {
  44. this.CurrentContext = null;
  45. }
  46. /// <summary>
  47. /// Should only be used by VisualLine.ConstructVisualElements.
  48. /// </summary>
  49. internal int cachedInterest;
  50. /// <summary>
  51. /// Gets the first offset >= startOffset where the generator wants to construct an element.
  52. /// Return -1 to signal no interest.
  53. /// </summary>
  54. public abstract int GetFirstInterestedOffset(int startOffset);
  55. /// <summary>
  56. /// Constructs an element at the specified offset.
  57. /// May return null if no element should be constructed.
  58. /// </summary>
  59. /// <remarks>
  60. /// Avoid signalling interest and then building no element by returning null - doing so
  61. /// causes the generated <see cref="VisualLineText"/> elements to be unnecessarily split
  62. /// at the position where you signalled interest.
  63. /// </remarks>
  64. public abstract VisualLineElement ConstructElement(int offset);
  65. }
  66. internal interface IBuiltinElementGenerator
  67. {
  68. void FetchOptions(TextEditorOptions options);
  69. }
  70. }