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