CefListValue.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. namespace Xilium.CefGlue
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. using Xilium.CefGlue.Interop;
  8. /// <summary>
  9. /// Class representing a list value. Can be used on any process and thread.
  10. /// </summary>
  11. public sealed unsafe partial class CefListValue : ICefListValue
  12. {
  13. /// <summary>
  14. /// Creates a new object that is not owned by any other object.
  15. /// </summary>
  16. public static CefListValue Create()
  17. {
  18. return CefListValue.FromNative(
  19. cef_list_value_t.create()
  20. );
  21. }
  22. /// <summary>
  23. /// Returns true if this object is valid. This object may become invalid if
  24. /// the underlying data is owned by another object (e.g. list or dictionary)
  25. /// and that other object is then modified or destroyed. Do not call any other
  26. /// methods if this method returns false.
  27. /// </summary>
  28. public bool IsValid
  29. {
  30. get { return cef_list_value_t.is_valid(_self) != 0; }
  31. }
  32. /// <summary>
  33. /// Returns true if this object is currently owned by another object.
  34. /// </summary>
  35. public bool IsOwned
  36. {
  37. get { return cef_list_value_t.is_owned(_self) != 0; }
  38. }
  39. /// <summary>
  40. /// Returns true if the values of this object are read-only. Some APIs may
  41. /// expose read-only objects.
  42. /// </summary>
  43. public bool IsReadOnly
  44. {
  45. get { return cef_list_value_t.is_read_only(_self) != 0; }
  46. }
  47. /// <summary>
  48. /// Returns true if this object and |that| object have the same underlying
  49. /// data. If true modifications to this object will also affect |that| object
  50. /// and vice-versa.
  51. /// </summary>
  52. public bool IsSame(ICefListValue that)
  53. {
  54. return cef_list_value_t.is_same(_self, ((CefListValue)that).ToNative()) != 0;
  55. }
  56. /// <summary>
  57. /// Returns true if this object and |that| object have an equivalent underlying
  58. /// value but are not necessarily the same object.
  59. /// </summary>
  60. public bool IsEqual(ICefListValue that)
  61. {
  62. return cef_list_value_t.is_equal(_self, ((CefListValue)that).ToNative()) != 0;
  63. }
  64. /// <summary>
  65. /// Returns a writable copy of this object.
  66. /// </summary>
  67. public ICefListValue Copy()
  68. {
  69. return CefListValue.FromNative(
  70. cef_list_value_t.copy(_self)
  71. );
  72. }
  73. /// <summary>
  74. /// Sets the number of values. If the number of values is expanded all
  75. /// new value slots will default to type null. Returns true on success.
  76. /// </summary>
  77. public bool SetSize(int size)
  78. {
  79. return cef_list_value_t.set_size(_self, (UIntPtr)size) != 0;
  80. }
  81. /// <summary>
  82. /// Returns the number of values.
  83. /// </summary>
  84. public int Count
  85. {
  86. get { return (int)cef_list_value_t.get_size(_self); }
  87. }
  88. /// <summary>
  89. /// Removes all values. Returns true on success.
  90. /// </summary>
  91. public bool Clear()
  92. {
  93. return cef_list_value_t.clear(_self) != 0;
  94. }
  95. /// <summary>
  96. /// Removes the value at the specified index.
  97. /// </summary>
  98. public bool Remove(int index)
  99. {
  100. return cef_list_value_t.remove(_self, checked((UIntPtr)index)) != 0;
  101. }
  102. /// <summary>
  103. /// Returns the value type at the specified index.
  104. /// </summary>
  105. public CefValueType GetValueType(int index)
  106. {
  107. return cef_list_value_t.get_type(_self, checked((UIntPtr)index));
  108. }
  109. /// <summary>
  110. /// Returns the value at the specified index. For simple types the returned
  111. /// value will copy existing data and modifications to the value will not
  112. /// modify this object. For complex types (binary, dictionary and list) the
  113. /// returned value will reference existing data and modifications to the value
  114. /// will modify this object.
  115. /// </summary>
  116. public CefValue GetValue(int index)
  117. {
  118. return CefValue.FromNativeOrNull(
  119. cef_list_value_t.get_value(_self, checked((UIntPtr)index))
  120. );
  121. }
  122. /// <summary>
  123. /// Returns the value at the specified index as type bool.
  124. /// </summary>
  125. public bool GetBool(int index)
  126. {
  127. return cef_list_value_t.get_bool(_self, checked((UIntPtr)index)) != 0;
  128. }
  129. /// <summary>
  130. /// Returns the value at the specified index as type int.
  131. /// </summary>
  132. public int GetInt(int index)
  133. {
  134. return cef_list_value_t.get_int(_self, checked((UIntPtr)index));
  135. }
  136. /// <summary>
  137. /// Returns the value at the specified index as type double.
  138. /// </summary>
  139. public double GetDouble(int index)
  140. {
  141. return cef_list_value_t.get_double(_self, checked((UIntPtr)index));
  142. }
  143. /// <summary>
  144. /// Returns the value at the specified index as type string.
  145. /// </summary>
  146. public string GetString(int index)
  147. {
  148. var n_result = cef_list_value_t.get_string(_self, checked((UIntPtr)index));
  149. return cef_string_userfree.ToString(n_result);
  150. }
  151. /// <summary>
  152. /// Returns the value at the specified index as type binary. The returned
  153. /// value will reference existing data.
  154. /// </summary>
  155. public ICefBinaryValue GetBinary(int index)
  156. {
  157. return CefBinaryValue.FromNativeOrNull(
  158. cef_list_value_t.get_binary(_self, checked((UIntPtr)index))
  159. );
  160. }
  161. /// <summary>
  162. /// Returns the value at the specified index as type dictionary. The returned
  163. /// value will reference existing data and modifications to the value will
  164. /// modify this object.
  165. /// </summary>
  166. public ICefDictionaryValue GetDictionary(int index)
  167. {
  168. return CefDictionaryValue.FromNativeOrNull(
  169. cef_list_value_t.get_dictionary(_self, checked((UIntPtr)index))
  170. );
  171. }
  172. /// <summary>
  173. /// Returns the value at the specified index as type list. The returned
  174. /// value will reference existing data and modifications to the value will
  175. /// modify this object.
  176. /// </summary>
  177. public ICefListValue GetList(int index)
  178. {
  179. return CefListValue.FromNativeOrNull(
  180. cef_list_value_t.get_list(_self, checked((UIntPtr)index))
  181. );
  182. }
  183. /// <summary>
  184. /// Sets the value at the specified index. Returns true if the value was set
  185. /// successfully. If |value| represents simple data then the underlying data
  186. /// will be copied and modifications to |value| will not modify this object. If
  187. /// |value| represents complex data (binary, dictionary or list) then the
  188. /// underlying data will be referenced and modifications to |value| will modify
  189. /// this object.
  190. /// </summary>
  191. public bool SetValue(int index, CefValue value)
  192. {
  193. return cef_list_value_t.set_value(_self, checked((UIntPtr)index), value.ToNative()) != 0;
  194. }
  195. /// <summary>
  196. /// Sets the value at the specified index as type null. Returns true if the
  197. /// value was set successfully.
  198. /// </summary>
  199. public bool SetNull(int index)
  200. {
  201. return cef_list_value_t.set_null(_self, checked((UIntPtr)index)) != 0;
  202. }
  203. /// <summary>
  204. /// Sets the value at the specified index as type bool. Returns true if the
  205. /// value was set successfully.
  206. /// </summary>
  207. public bool SetBool(int index, bool value)
  208. {
  209. return cef_list_value_t.set_bool(_self, checked((UIntPtr)index), value ? 1 : 0) != 0;
  210. }
  211. /// <summary>
  212. /// Sets the value at the specified index as type int. Returns true if the
  213. /// value was set successfully.
  214. /// </summary>
  215. public bool SetInt(int index, int value)
  216. {
  217. return cef_list_value_t.set_int(_self, checked((UIntPtr)index), value) != 0;
  218. }
  219. /// <summary>
  220. /// Sets the value at the specified index as type double. Returns true if the
  221. /// value was set successfully.
  222. /// </summary>
  223. public bool SetDouble(int index, double value)
  224. {
  225. return cef_list_value_t.set_double(_self, checked((UIntPtr)index), value) != 0;
  226. }
  227. /// <summary>
  228. /// Sets the value at the specified index as type string. Returns true if the
  229. /// value was set successfully.
  230. /// </summary>
  231. public bool SetString(int index, string value)
  232. {
  233. fixed (char* value_str = value)
  234. {
  235. var n_value = new cef_string_t(value_str, value != null ? value.Length : 0);
  236. return cef_list_value_t.set_string(_self, checked((UIntPtr)index), &n_value) != 0;
  237. }
  238. }
  239. /// <summary>
  240. /// Sets the value at the specified index as type binary. Returns true if the
  241. /// value was set successfully. If |value| is currently owned by another object
  242. /// then the value will be copied and the |value| reference will not change.
  243. /// Otherwise, ownership will be transferred to this object and the |value|
  244. /// reference will be invalidated.
  245. /// </summary>
  246. public bool SetBinary(int index, ICefBinaryValue value)
  247. {
  248. return cef_list_value_t.set_binary(_self, checked((UIntPtr)index), ((CefBinaryValue)value).ToNative()) != 0;
  249. }
  250. /// <summary>
  251. /// Sets the value at the specified index as type dict. Returns true if the
  252. /// value was set successfully. If |value| is currently owned by another object
  253. /// then the value will be copied and the |value| reference will not change.
  254. /// Otherwise, ownership will be transferred to this object and the |value|
  255. /// reference will be invalidated.
  256. /// </summary>
  257. public bool SetDictionary(int index, ICefDictionaryValue value)
  258. {
  259. return cef_list_value_t.set_dictionary(_self, checked((UIntPtr)index), ((CefDictionaryValue)value).ToNative()) != 0;
  260. }
  261. /// <summary>
  262. /// Sets the value at the specified index as type list. Returns true if the
  263. /// value was set successfully. If |value| is currently owned by another object
  264. /// then the value will be copied and the |value| reference will not change.
  265. /// Otherwise, ownership will be transferred to this object and the |value|
  266. /// reference will be invalidated.
  267. /// </summary>
  268. public bool SetList(int index, ICefListValue value)
  269. {
  270. return cef_list_value_t.set_list(_self, checked((UIntPtr)index), ((CefListValue)value).ToNative()) != 0;
  271. }
  272. }
  273. }