#region Using Directives using System; using System.Collections; using System.ComponentModel; using ScintillaNET.Design; using ScintillaNET.Properties; #endregion Using Directives namespace ScintillaNET { /// /// Represents a collection of objects and options in a control. /// /// /// Annotations are customizable read-only blocks of text which can be displayed below /// each line in a control. /// [TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))] public class AnnotationCollection : /*ICollection,*/ IEnumerable { #region Fields private Scintilla _scintilla; #endregion Fields #region Methods /// /// Removes all annotations from the document. /// /// This is equivalent to setting the property to null for each line. public virtual void ClearAll() { _scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONCLEARALL, IntPtr.Zero, IntPtr.Zero); } /* /// /// Copies the entire to a compatible one-dimensional . /// /// The one-dimensional that is the destination of the annotations. /// The zero-based index in at which copying begins. /// is null. /// is less than zero. /// /// is multidimensional. -or- /// The number of annotations in the source is greater than /// the available space from to the end of the destination . /// /// /// The type of the source cannot be cast /// automatically to the type of the destination . /// public void CopyTo(Array array, int index) { if (array == null) throw new ArgumentNullException("array"); if (index < 0 || index > array.Length) throw new ArgumentOutOfRangeException("index", Resources.Exception_IndexOutOfRange); if (array.Length - index < Count) throw new ArgumentException(Resources.Exception_InsufficientSpace); for (int i = 0; i < Count; i++) array.SetValue(this[i], index + i); } */ /// /// Creates and returns a new object. /// /// A new object. [EditorBrowsable(EditorBrowsableState.Advanced)] protected virtual Annotation CreateAnnotationInstance(int lineIndex) { return new Annotation(_scintilla, lineIndex); } /// /// Returns an enumerator for the . /// /// An for the . public virtual IEnumerator GetEnumerator() { return new AnnotationCollectionEnumerator(this); } internal bool ShouldSerialize() { return Visibility != AnnotationsVisibility.Hidden; } #endregion Methods #region Properties /// /// Gets the number of annotations in the . /// /// The number of annotations contained in the . /// /// As there can be one annotation per document line, /// this is equivalent to the property. /// [Browsable(false)] public int Count { get { return _scintilla.Lines.Count; } } /* bool ICollection.IsSynchronized { get { return false; } } object ICollection.SyncRoot { get { return this; } } */ /// /// Gets or sets the offset applied to style indexes used in annotations. /// /// The offset applied to style indexes used in annotations. /// /// Annotation styles may be completely separated from standard text styles by setting a style offset. /// For example, a value of 512 would shift the range of possible annotation styles to be from 512 to 767 /// so they do not overlap with standard text styles. This adjustment is applied automatically when setting /// or calling so the offset should NOT be /// manually factored in by the caller. This property is provided to maintain architectural symmetry with /// the native Scintilla component but is an advanced feature and typically should never need to be changed. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Advanced)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public int StyleOffset { get { return _scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETSTYLEOFFSET, IntPtr.Zero, IntPtr.Zero).ToInt32(); } set { // I contemplated throwing an exception if the argument is out of range, however, this being an // advanced feature I'm going to leave it for the advanced user to figure out for now. _scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONSETSTYLEOFFSET, new IntPtr(value), IntPtr.Zero); } } /// /// Gets or sets the visibility style for all annotations. /// /// /// One of the values. /// The default is . /// /// /// The value assigned is not one of the values. /// [DefaultValue(AnnotationsVisibility.Hidden)] [Description("Indicates the visibility and appearance of annotations.")] // TODO Move to resource file public AnnotationsVisibility Visibility { get { return (AnnotationsVisibility)_scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETVISIBLE, IntPtr.Zero, IntPtr.Zero); } set { if (!Enum.IsDefined(typeof(AnnotationsVisibility), value)) throw new InvalidEnumArgumentException("value", (int)value, typeof(AnnotationsVisibility)); _scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONSETVISIBLE, new IntPtr((int)value), IntPtr.Zero); } } #endregion Properties #region Indexers /// /// Gets the annotation at the specified line index. /// /// The zero-based document line index of the annotation to get. /// The at the specified line index. /// /// is less than zero. -or- /// is equal to or greater than . /// public Annotation this[int lineIndex] { get { if (lineIndex < 0 || lineIndex > Count - 1) throw new ArgumentOutOfRangeException("lineIndex", Resources.Exception_IndexOutOfRange); // Use our Create method so others can override this class and provide custom annotations return CreateAnnotationInstance(lineIndex); } } #endregion Indexers #region Constructors /// /// Initializes a new instance of the class. /// /// The control that created this object. protected internal AnnotationCollection(Scintilla scintilla) { _scintilla = scintilla; } #endregion Constructors #region Types // Just enough to get the job done... private class AnnotationCollectionEnumerator : IEnumerator { private AnnotationCollection _collection; private int _index; public bool MoveNext() { _index++; if (_index >= _collection.Count) return false; return true; } public void Reset() { _index = -1; } public object Current { get { if (_index == -1) throw new InvalidOperationException(Resources.Exception_EnumeratorNotStarted); try { return _collection[_index]; } catch(ArgumentOutOfRangeException) { throw new InvalidOperationException(Resources.Exception_EnumeratorEnded); } } } public AnnotationCollectionEnumerator(AnnotationCollection collection) { _collection = collection; Reset(); } } #endregion Types } }