#region Using Directives using System; using System.ComponentModel; using System.Drawing.Design; using System.Globalization; using ScintillaNET.Design; using ScintillaNET.Properties; #endregion Using Directives namespace ScintillaNET { /// /// Controls line wrapping options in a control. /// [TypeConverterAttribute(typeof(ExpandableObjectConverter))] public class LineWrapping { #region Fields private Scintilla _scintilla; #endregion Fields #region Methods /// /// The number of lines displayed when a line of text is wrapped. /// /// The zero-based index of the line to count. /// The numbers of display lines the line of text occupies. ///// ///// is less than 0 or greater than the line count. ///// public virtual int GetWrapCount(int lineIndex) { //if (lineIndex < 0 || lineIndex > _scintilla.Lines.Count) //{ // string paramName = "lineIndex"; // string message = string.Format(CultureInfo.InvariantCulture, Resources.Exception_MustBeNonNegativeAndLessThan, paramName, "the line count"); // throw new ArgumentOutOfRangeException(paramName, message); //} return _scintilla.DirectMessage(NativeMethods.SCI_WRAPCOUNT, new IntPtr(lineIndex), IntPtr.Zero).ToInt32(); } internal bool ShouldSerialize() { return IndentMode != LineWrappingIndentMode.Fixed || IndentSize != 0 || Mode != LineWrappingMode.None || VisualFlags != LineWrappingVisualFlags.None || VisualFlagsLocations != LineWrappingVisualFlagsLocations.Default; } /// /// Forces the line range specified to wrap at the given pixel width. This operates independently /// of the current line wrapping property. /// /// The zero-based line index to start wrapping. /// The zero-based line index to stop wrapping. /// /// The maximum width in pixels of the lines to wrap. A value of zero resets forced line wrapping. /// ///// ///// and do not specify a valid ///// range of lines within the document. ///// public virtual void WrapLines(int startLine, int endLine, int width) { //if (startLine < 0) // throw new ArgumentOutOfRangeException("startLine", Resources.Exception_InvalidStartLine); //if (endLine < startLine) // throw new ArgumentOutOfRangeException("endLine", Resources.Exception_InvalidLineRange); // Convert line indexes to positions within the line int startPos = _scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(startLine), IntPtr.Zero).ToInt32(); int endPos = _scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(endLine), IntPtr.Zero).ToInt32(); //if (startPos == -1) // throw new ArgumentOutOfRangeException("startLine", string.Format(CultureInfo.InvariantCulture, Resources.Exception_InvalidLine, "start")); //if (endPos == -1) // throw new ArgumentOutOfRangeException("endLine", string.Format(CultureInfo.InvariantCulture, Resources.Exception_InvalidLine, "end")); // Set the target positions (which Scintilla will convert back to line indexes) _scintilla.DirectMessage(NativeMethods.SCI_SETTARGETSTART, new IntPtr(startPos), IntPtr.Zero); _scintilla.DirectMessage(NativeMethods.SCI_SETTARGETEND, new IntPtr(endPos), IntPtr.Zero); _scintilla.DirectMessage(NativeMethods.SCI_LINESSPLIT, new IntPtr(width), IntPtr.Zero); } #endregion Methods #region Properties /// /// Gets or sets how wrapped lines are indented. /// /// /// One of the values. /// The default is . /// /// /// The value assigned is not one of the values. /// [DefaultValue(LineWrappingIndentMode.Fixed)] [Description("Indicates how wrapped lines are indented.")] // TODO Move to resource file. public virtual LineWrappingIndentMode IndentMode { get { return (LineWrappingIndentMode)_scintilla.DirectMessage( NativeMethods.SCI_GETWRAPINDENTMODE, IntPtr.Zero, IntPtr.Zero); } set { if (!Enum.IsDefined(typeof(LineWrappingIndentMode), value)) throw new InvalidEnumArgumentException("value", (int)value, typeof(LineWrappingIndentMode)); _scintilla.DirectMessage(NativeMethods.SCI_SETWRAPINDENTMODE, new IntPtr((int)value), IntPtr.Zero); } } /// /// Gets or sets the size that wrapped lines are indented when is . /// /// An representing the size (in characters) that wrapped lines are indented. /// The value is less that zero or greater than 256. [DefaultValue(0)] [Description("The indentation size of wrapped lines.")] // TODO Move to resource file. public virtual int IndentSize { get { return _scintilla.DirectMessage(NativeMethods.SCI_GETWRAPSTARTINDENT, IntPtr.Zero, IntPtr.Zero).ToInt32(); } set { // A max of 256 is something I came up with myself. // It's probably way too high, but I would rather that than make it too low. const int max = 256; if (value < 0 || value > max) { const string paramName = "value"; string message = string.Format(CultureInfo.InvariantCulture, Resources.Exception_MustBeNonNegativeAndLessThan, paramName, max); throw new ArgumentOutOfRangeException(paramName, message); } _scintilla.DirectMessage(NativeMethods.SCI_SETWRAPSTARTINDENT, new IntPtr(value), IntPtr.Zero); } } /// /// Gets or sets how and whether line wrapping is performed. /// /// /// One of the values. /// The default is . /// /// /// The value assigned is not one of the values. /// [DefaultValue(LineWrappingMode.None)] [Description("Specifies how and whether line wrapping is performed.")] // TODO Move to resource file. public virtual LineWrappingMode Mode { get { return (LineWrappingMode)_scintilla.DirectMessage( NativeMethods.SCI_GETWRAPMODE, IntPtr.Zero, IntPtr.Zero); } set { if (!Enum.IsDefined(typeof(LineWrappingMode), value)) throw new InvalidEnumArgumentException("value", (int)value, typeof(LineWrappingMode)); _scintilla.DirectMessage(NativeMethods.SCI_SETWRAPMODE, new IntPtr((int)value), IntPtr.Zero); } } /// /// Gets or sets the visual glyphs displayed on wrapped lines. /// /// /// A bitwise combination of the values. /// The default is . /// [DefaultValue(LineWrappingVisualFlags.None)] [Description("Specifies the visual indicators on wrapped lines.")] // TODO Move to resource file. [Editor(typeof(FlagEnumUIEditor), typeof(UITypeEditor))] public virtual LineWrappingVisualFlags VisualFlags { get { return (LineWrappingVisualFlags)_scintilla.DirectMessage( NativeMethods.SCI_GETWRAPVISUALFLAGS, IntPtr.Zero, IntPtr.Zero); } set { _scintilla.DirectMessage(NativeMethods.SCI_SETWRAPVISUALFLAGS, new IntPtr((int)value), IntPtr.Zero); } } /// /// Gets or sets the location of visual glyphs displayed on wrapped lines. /// /// /// A bitwise combination of the values. /// The default is . /// [DefaultValue(LineWrappingVisualFlagsLocations.Default)] [Description("Specifies the location of visual indicators on wrapped lines.")] // TODO Move to resource file. [Editor(typeof(FlagEnumUIEditor), typeof(UITypeEditor))] public virtual LineWrappingVisualFlagsLocations VisualFlagsLocations { get { return (LineWrappingVisualFlagsLocations)_scintilla.DirectMessage( NativeMethods.SCI_GETWRAPVISUALFLAGSLOCATION, IntPtr.Zero, IntPtr.Zero); } set { _scintilla.DirectMessage(NativeMethods.SCI_SETWRAPVISUALFLAGSLOCATION, new IntPtr((int)value), IntPtr.Zero); } } #endregion Properties #region Constructors /// /// Initializes a new instance of the class. /// /// The control that created this object. protected internal LineWrapping(Scintilla scintilla) { _scintilla = scintilla; } #endregion Constructors } }