GatewayDomain.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. // NPP plugin platform for .Net v0.94.00 by Kasper B. Graversen etc.
  2. using System;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. namespace Kbg.NppPluginNET.PluginInfrastructure
  6. {
  7. /// <summary>
  8. /// Colours are set using the RGB format (Red, Green, Blue). The intensity of each colour is set in the range 0 to 255.
  9. /// If you have three such intensities, they are combined as: red | (green &lt;&lt; 8) | (blue &lt;&lt; 16).
  10. /// If you set all intensities to 255, the colour is white. If you set all intensities to 0, the colour is black.
  11. /// When you set a colour, you are making a request. What you will get depends on the capabilities of the system and the current screen mode.
  12. /// </summary>
  13. public class Colour
  14. {
  15. public readonly int Red, Green, Blue;
  16. public Colour(int rgb)
  17. {
  18. Red = rgb & 0xFF;
  19. Green = (rgb >> 8) & 0xFF;
  20. Blue = (rgb >> 16) & 0xFF;
  21. }
  22. /// <summary>
  23. ///
  24. /// </summary>
  25. /// <param name="red">a number 0-255</param>
  26. /// <param name="green">a number 0-255</param>
  27. /// <param name="blue">a number 0-255</param>
  28. public Colour(int red, int green, int blue)
  29. {
  30. if(red > 255 || red < 0)
  31. throw new ArgumentOutOfRangeException("red", "must be 0-255");
  32. if(green > 255 || green < 0)
  33. throw new ArgumentOutOfRangeException("green", "must be 0-255");
  34. if(blue > 255 || blue < 0)
  35. throw new ArgumentOutOfRangeException("blue", "must be 0-255");
  36. Red = red;
  37. Green = green;
  38. Blue = blue;
  39. }
  40. public int Value
  41. {
  42. get { return Red + (Green << 8) + (Blue << 16); }
  43. }
  44. }
  45. /// <summary>
  46. /// Positions within the Scintilla document refer to a character or the gap before that character.
  47. /// The first character in a document is 0, the second 1 and so on. If a document contains nLen characters, the last character is numbered nLen-1. The caret exists between character positions and can be located from before the first character (0) to after the last character (nLen).
  48. ///
  49. /// There are places where the caret can not go where two character bytes make up one character.
  50. /// This occurs when a DBCS character from a language like Japanese is included in the document or when line ends are marked with the CP/M
  51. /// standard of a carriage return followed by a line feed.The INVALID_POSITION constant(-1) represents an invalid position within the document.
  52. ///
  53. /// All lines of text in Scintilla are the same height, and this height is calculated from the largest font in any current style.This restriction
  54. /// is for performance; if lines differed in height then calculations involving positioning of text would require the text to be styled first.
  55. ///
  56. /// If you use messages, there is nothing to stop you setting a position that is in the middle of a CRLF pair, or in the middle of a 2 byte character.
  57. /// However, keyboard commands will not move the caret into such positions.
  58. /// </summary>
  59. public class Position : IEquatable<Position>
  60. {
  61. private readonly int pos;
  62. public Position(int pos)
  63. {
  64. this.pos = pos;
  65. }
  66. public int Value
  67. {
  68. get { return pos; }
  69. }
  70. public static Position operator +(Position a, Position b)
  71. {
  72. return new Position(a.pos + b.pos);
  73. }
  74. public static Position operator -(Position a, Position b)
  75. {
  76. return new Position(a.pos - b.pos);
  77. }
  78. public static bool operator ==(Position a, Position b)
  79. {
  80. if (ReferenceEquals(a, b))
  81. return true;
  82. if (ReferenceEquals(a, null))
  83. return false;
  84. if (ReferenceEquals(b, null))
  85. return false;
  86. return a.pos == b.pos;
  87. }
  88. public static bool operator !=(Position a, Position b)
  89. {
  90. return !(a == b);
  91. }
  92. public static bool operator >(Position a, Position b)
  93. {
  94. return a.Value > b.Value;
  95. }
  96. public static bool operator <(Position a, Position b)
  97. {
  98. return a.Value < b.Value;
  99. }
  100. public static Position Min(Position a, Position b)
  101. {
  102. if (a < b)
  103. return a;
  104. return b;
  105. }
  106. public static Position Max(Position a, Position b)
  107. {
  108. if (a > b)
  109. return a;
  110. return b;
  111. }
  112. public override string ToString()
  113. {
  114. return "Postion: " + pos;
  115. }
  116. public bool Equals(Position other)
  117. {
  118. if (ReferenceEquals(null, other)) return false;
  119. if (ReferenceEquals(this, other)) return true;
  120. return pos == other.pos;
  121. }
  122. public override bool Equals(object obj)
  123. {
  124. if (ReferenceEquals(null, obj)) return false;
  125. if (ReferenceEquals(this, obj)) return true;
  126. if (obj.GetType() != this.GetType()) return false;
  127. return Equals((Position)obj);
  128. }
  129. public override int GetHashCode()
  130. {
  131. return pos;
  132. }
  133. }
  134. /// <summary>
  135. /// Class containing key and modifiers
  136. ///
  137. /// The key code is a visible or control character or a key from the SCK_* enumeration, which contains:
  138. /// SCK_ADD, SCK_BACK, SCK_DELETE, SCK_DIVIDE, SCK_DOWN, SCK_END, SCK_ESCAPE, SCK_HOME, SCK_INSERT, SCK_LEFT, SCK_MENU, SCK_NEXT(Page Down), SCK_PRIOR(Page Up), S
  139. /// CK_RETURN, SCK_RIGHT, SCK_RWIN, SCK_SUBTRACT, SCK_TAB, SCK_UP, and SCK_WIN.
  140. ///
  141. /// The modifiers are a combination of zero or more of SCMOD_ALT, SCMOD_CTRL, SCMOD_SHIFT, SCMOD_META, and SCMOD_SUPER.
  142. /// On OS X, the Command key is mapped to SCMOD_CTRL and the Control key to SCMOD_META.SCMOD_SUPER is only available on GTK+ which is commonly the Windows key.
  143. /// If you are building a table, you might want to use SCMOD_NORM, which has the value 0, to mean no modifiers.
  144. /// </summary>
  145. public class KeyModifier
  146. {
  147. private readonly int value;
  148. /// <summary>
  149. /// The key code is a visible or control character or a key from the SCK_* enumeration, which contains:
  150. /// SCK_ADD, SCK_BACK, SCK_DELETE, SCK_DIVIDE, SCK_DOWN, SCK_END, SCK_ESCAPE, SCK_HOME, SCK_INSERT, SCK_LEFT, SCK_MENU, SCK_NEXT(Page Down), SCK_PRIOR(Page Up),
  151. /// SCK_RETURN, SCK_RIGHT, SCK_RWIN, SCK_SUBTRACT, SCK_TAB, SCK_UP, and SCK_WIN.
  152. ///
  153. /// The modifiers are a combination of zero or more of SCMOD_ALT, SCMOD_CTRL, SCMOD_SHIFT, SCMOD_META, and SCMOD_SUPER.
  154. /// On OS X, the Command key is mapped to SCMOD_CTRL and the Control key to SCMOD_META.SCMOD_SUPER is only available on GTK+ which is commonly the Windows key.
  155. /// If you are building a table, you might want to use SCMOD_NORM, which has the value 0, to mean no modifiers.
  156. /// </summary>
  157. public KeyModifier(SciMsg SCK_KeyCode, SciMsg SCMOD_modifier)
  158. {
  159. value = (int) SCK_KeyCode | ((int) SCMOD_modifier << 16);
  160. }
  161. public int Value
  162. {
  163. get { return Value; }
  164. }
  165. }
  166. [StructLayout(LayoutKind.Sequential)]
  167. public struct CharacterRange
  168. {
  169. public CharacterRange(int cpmin, int cpmax) { cpMin = cpmin; cpMax = cpmax; }
  170. public int cpMin;
  171. public int cpMax;
  172. }
  173. public class Cells
  174. {
  175. char[] charactersAndStyles;
  176. public Cells(char[] charactersAndStyles)
  177. {
  178. this.charactersAndStyles = charactersAndStyles;
  179. }
  180. public char[] Value { get { return charactersAndStyles; } }
  181. }
  182. public class TextRange : IDisposable
  183. {
  184. Sci_TextRange _sciTextRange;
  185. IntPtr _ptrSciTextRange;
  186. bool _disposed = false;
  187. public TextRange(CharacterRange chrRange, int stringCapacity)
  188. {
  189. _sciTextRange.chrg = chrRange;
  190. _sciTextRange.lpstrText = Marshal.AllocHGlobal(stringCapacity);
  191. }
  192. public TextRange(int cpmin, int cpmax, int stringCapacity)
  193. {
  194. _sciTextRange.chrg.cpMin = cpmin;
  195. _sciTextRange.chrg.cpMax = cpmax;
  196. _sciTextRange.lpstrText = Marshal.AllocHGlobal(stringCapacity);
  197. }
  198. [StructLayout(LayoutKind.Sequential)]
  199. struct Sci_TextRange
  200. {
  201. public CharacterRange chrg;
  202. public IntPtr lpstrText;
  203. }
  204. public IntPtr NativePointer { get { _initNativeStruct(); return _ptrSciTextRange; } }
  205. public string lpstrText { get { _readNativeStruct(); return Marshal.PtrToStringAnsi(_sciTextRange.lpstrText); } }
  206. public CharacterRange chrg { get { _readNativeStruct(); return _sciTextRange.chrg; } set { _sciTextRange.chrg = value; _initNativeStruct(); } }
  207. void _initNativeStruct()
  208. {
  209. if (_ptrSciTextRange == IntPtr.Zero)
  210. _ptrSciTextRange = Marshal.AllocHGlobal(Marshal.SizeOf(_sciTextRange));
  211. Marshal.StructureToPtr(_sciTextRange, _ptrSciTextRange, false);
  212. }
  213. void _readNativeStruct()
  214. {
  215. if (_ptrSciTextRange != IntPtr.Zero)
  216. _sciTextRange = (Sci_TextRange)Marshal.PtrToStructure(_ptrSciTextRange, typeof(Sci_TextRange));
  217. }
  218. public void Dispose()
  219. {
  220. if (!_disposed)
  221. {
  222. if (_sciTextRange.lpstrText != IntPtr.Zero) Marshal.FreeHGlobal(_sciTextRange.lpstrText);
  223. if (_ptrSciTextRange != IntPtr.Zero) Marshal.FreeHGlobal(_ptrSciTextRange);
  224. _disposed = true;
  225. }
  226. }
  227. ~TextRange()
  228. {
  229. Dispose();
  230. }
  231. }
  232. /* ++Autogenerated -- start of section automatically generated from Scintilla.iface */
  233. /* --Autogenerated -- end of section automatically generated from Scintilla.iface */
  234. }