Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IMenuModel.cs 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. // Copyright © 2013 The CefSharp Authors. All rights reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
  4. namespace CefSharp
  5. {
  6. /// <summary>
  7. /// Supports creation and modification of menus. See <see cref="CefMenuCommand"/> for the command ids that have default implementations.
  8. /// All user-defined command ids should be between <see cref="CefMenuCommand.UserFirst"/> and <see cref="CefMenuCommand.UserFirst"/>.
  9. /// The methods of this class can only be accessed on the CEF UI thread, which by default is not the same as your application UI thread.
  10. /// </summary>
  11. public interface IMenuModel
  12. {
  13. /// <summary>
  14. /// Returns the number of items in this menu.
  15. /// </summary>
  16. int Count { get; }
  17. /// <summary>
  18. /// Remove all menu items. Can be used to disable the context menu. Returns true on success.
  19. /// </summary>
  20. /// <returns>Returns true on success</returns>
  21. bool Clear();
  22. /// <summary>
  23. /// Returns the label at the specified index or empty if not found due to
  24. /// invalid range or the index being a separator.
  25. /// </summary>
  26. /// <param name="index">specified index</param>
  27. /// <returns>Label or empty if not found due to invalid range or the index being a separator.</returns>
  28. string GetLabelAt(int index);
  29. /// <summary>
  30. /// Returns the command id at the specified index or -1 if not found due to invalid range or the index being a separator.
  31. /// </summary>
  32. /// <param name="index">the index</param>
  33. /// <returns>Command or -1 if not found due to invalid range or the index being a separator.</returns>
  34. CefMenuCommand GetCommandIdAt(int index);
  35. /// <summary>
  36. /// Removes the item with the specified commandId.
  37. /// </summary>
  38. /// <param name="commandId">the command Id</param>
  39. /// <returns>Returns true on success</returns>
  40. bool Remove(CefMenuCommand commandId);
  41. /// <summary>
  42. /// Add an item to the menu.
  43. /// </summary>
  44. /// <param name="commandId">the command Id</param>
  45. /// <param name="label">the label of the item</param>
  46. /// <returns>Returns true on success.</returns>
  47. bool AddItem(CefMenuCommand commandId, string label);
  48. /// <summary>
  49. /// Add a separator to the menu.
  50. /// </summary>
  51. /// <returns>Returns true on success.</returns>
  52. bool AddSeparator();
  53. /// <summary>
  54. /// Add a check item to the menu.
  55. /// </summary>
  56. /// <param name="commandId">the command Id</param>
  57. /// <param name="label">the label of the item</param>
  58. /// <returns>Returns true on success.</returns>
  59. bool AddCheckItem(CefMenuCommand commandId, string label);
  60. /// <summary>
  61. /// Add a radio item to the menu. Only a single item with the specified groupId can be checked at a time.
  62. /// </summary>
  63. /// <param name="commandId">the command Id</param>
  64. /// <param name="label">the label of the item</param>
  65. /// <param name="groupId">the group id</param>
  66. /// <returns>Returns true on success.</returns>
  67. bool AddRadioItem(CefMenuCommand commandId, string label, int groupId);
  68. /// <summary>
  69. /// Add a sub-menu to the menu. The new sub-menu is returned.
  70. /// </summary>
  71. /// <param name="commandId">the command Id</param>
  72. /// <param name="label">the label of the item</param>
  73. /// <returns>Returns the newly created <see cref="IMenuModel"/>.</returns>
  74. IMenuModel AddSubMenu(CefMenuCommand commandId, string label);
  75. /// <summary>
  76. /// Insert a separator in the menu at the specified index.
  77. /// </summary>
  78. /// <param name="index">index</param>
  79. /// <returns>Returns true on success.</returns>
  80. bool InsertSeparatorAt(int index);
  81. /// <summary>
  82. /// Insert an item in the menu at the specified index.
  83. /// </summary>
  84. /// <param name="index">index</param>
  85. /// <param name="commandId">the command Id</param>
  86. /// <param name="label">the label of the item</param>
  87. /// <returns>Returns true on success.</returns>
  88. bool InsertItemAt(int index, CefMenuCommand commandId, string label);
  89. /// <summary>
  90. /// Insert a check item in the menu at the specified index.
  91. /// </summary>
  92. /// <param name="index">index</param>
  93. /// <param name="commandId">the command Id</param>
  94. /// <param name="label">the label of the item</param>
  95. /// <returns>Returns true on success.</returns>
  96. bool InsertCheckItemAt(int index, CefMenuCommand commandId, string label);
  97. /// <summary>
  98. /// Insert a radio item in the menu at the specified index.
  99. /// Only a single item with the specified groupId can be checked at a time.
  100. /// </summary>
  101. /// <param name="index">index</param>
  102. /// <param name="commandId">the command Id</param>
  103. /// <param name="label">the label of the item</param>
  104. /// <param name="groupId">the group id</param>
  105. /// <returns>Returns true on success.</returns>
  106. bool InsertRadioItemAt(int index, CefMenuCommand commandId, string label, int groupId);
  107. /// <summary>
  108. /// Insert a sub-menu in the menu at the specified index.
  109. /// </summary>
  110. /// <param name="index">index</param>
  111. /// <param name="commandId">the command Id</param>
  112. /// <param name="label">the label of the item</param>
  113. /// <returns>Returns the newly created <see cref="IMenuModel"/>.</returns>
  114. IMenuModel InsertSubMenuAt(int index, CefMenuCommand commandId, string label);
  115. /// <summary>
  116. /// Removes the item at the specified index.
  117. /// </summary>
  118. /// <param name="index">index</param>
  119. /// <returns>Returns true on success.</returns>
  120. bool RemoveAt(int index);
  121. /// <summary>
  122. /// Returns the index associated with the specified commandId or -1 if not found due to the command id not existing in the menu.
  123. /// </summary>
  124. /// <param name="commandId">the command Id</param>
  125. /// <returns>Returns the index associated with the specified commandId or -1 if not found due to the command id not existing in the menu.</returns>
  126. int GetIndexOf(CefMenuCommand commandId);
  127. /// <summary>
  128. /// Sets the command id at the specified index.
  129. /// </summary>
  130. /// <param name="index">index</param>
  131. /// <param name="commandId">the command Id</param>
  132. /// <returns>Returns true on success.</returns>
  133. bool SetCommandIdAt(int index, CefMenuCommand commandId);
  134. /// <summary>
  135. /// Returns the label for the specified commandId or empty if not found.
  136. /// </summary>
  137. /// <param name="commandId">the command Id</param>
  138. /// <returns>Returns the label for the specified commandId or empty if not found.</returns>
  139. string GetLabel(CefMenuCommand commandId);
  140. /// <summary>
  141. /// Sets the label for the specified commandId.
  142. /// </summary>
  143. /// <param name="commandId">the command Id</param>
  144. /// <param name="label">the label</param>
  145. /// <returns>Returns true on success.</returns>
  146. bool SetLabel(CefMenuCommand commandId, string label);
  147. /// <summary>
  148. /// Set the label at the specified index.
  149. /// </summary>
  150. /// <param name="index">index</param>
  151. /// <param name="label">the label</param>
  152. /// <returns>Returns true on success.</returns>
  153. bool SetLabelAt(int index, string label);
  154. /// <summary>
  155. /// Returns the item type for the specified commandId.
  156. /// </summary>
  157. /// <param name="commandId">the command Id</param>
  158. /// <returns>Returns the item type for the specified commandId.</returns>
  159. MenuItemType GetType(CefMenuCommand commandId);
  160. /// <summary>
  161. /// Returns the item type at the specified index.
  162. /// </summary>
  163. /// <param name="index">index</param>
  164. /// <returns>Returns the item type at the specified index.</returns>
  165. MenuItemType GetTypeAt(int index);
  166. /// <summary>
  167. /// Returns the group id for the specified commandId or -1 if invalid.
  168. /// </summary>
  169. /// <param name="commandId">the command Id</param>
  170. /// <returns>Returns the group id for the specified commandId or -1 if invalid.</returns>
  171. int GetGroupId(CefMenuCommand commandId);
  172. /// <summary>
  173. /// Returns the group id at the specified index or -1 if invalid.
  174. /// </summary>
  175. /// <param name="index">index</param>
  176. /// <returns>Returns the group id at the specified index or -1 if invalid.</returns>
  177. int GetGroupIdAt(int index);
  178. /// <summary>
  179. /// Sets the group id for the specified commandId.
  180. /// </summary>
  181. /// <param name="commandId">the command Id</param>
  182. /// <param name="groupId">the group id</param>
  183. /// <returns>Returns true on success.</returns>
  184. bool SetGroupId(CefMenuCommand commandId, int groupId);
  185. /// <summary>
  186. /// Sets the group id at the specified index.
  187. /// </summary>
  188. /// <param name="index">index</param>
  189. /// <param name="groupId">the group id</param>
  190. /// <returns>Returns true on success.</returns>
  191. bool SetGroupIdAt(int index, int groupId);
  192. /// <summary>
  193. /// Returns the <see cref="IMenuModel"/> for the specified commandId or null if invalid.
  194. /// </summary>
  195. /// <param name="commandId">the command Id</param>
  196. /// <returns>Returns the <see cref="IMenuModel"/> for the specified commandId or null if invalid.</returns>
  197. IMenuModel GetSubMenu(CefMenuCommand commandId);
  198. /// <summary>
  199. /// Returns the <see cref="IMenuModel"/> at the specified index or empty if invalid.
  200. /// </summary>
  201. /// <param name="index">index</param>
  202. /// <returns>Returns the <see cref="IMenuModel"/> for the specified commandId or null if invalid.</returns>
  203. IMenuModel GetSubMenuAt(int index);
  204. /// <summary>
  205. /// Returns true if the specified commandId is visible.
  206. /// </summary>
  207. /// <param name="commandId">the command Id</param>
  208. /// <returns>Returns true if the specified commandId is visible.</returns>
  209. bool IsVisible(CefMenuCommand commandId);
  210. /// <summary>
  211. /// Returns true if the specified index is visible.
  212. /// </summary>
  213. /// <param name="index">index</param>
  214. /// <returns>Returns true if the specified index is visible.</returns>
  215. bool IsVisibleAt(int index);
  216. /// <summary>
  217. /// Change the visibility of the specified commandId.
  218. /// </summary>
  219. /// <param name="commandId">the command Id</param>
  220. /// <param name="visible">visible</param>
  221. /// <returns>Returns true on success.</returns>
  222. bool SetVisible(CefMenuCommand commandId, bool visible);
  223. /// <summary>
  224. /// Change the visibility at the specified index.
  225. /// </summary>
  226. /// <param name="index">index</param>
  227. /// <param name="visible">visible</param>
  228. /// <returns>Returns true on success.</returns>
  229. bool SetVisibleAt(int index, bool visible);
  230. /// <summary>
  231. /// Returns true if the specified commandId is enabled.
  232. /// </summary>
  233. /// <param name="commandId">the command Id</param>
  234. /// <returns>Returns true if the specified commandId is enabled.</returns>
  235. bool IsEnabled(CefMenuCommand commandId);
  236. /// <summary>
  237. /// Returns true if the specified index is enabled.
  238. /// </summary>
  239. /// <param name="index">index</param>
  240. /// <returns>Returns true if the specified index is enabled.</returns>
  241. bool IsEnabledAt(int index);
  242. /// <summary>
  243. /// Change the enabled status of the specified commandId.
  244. /// </summary>
  245. /// <param name="commandId">the command Id</param>
  246. /// <param name="enabled">is enabled</param>
  247. /// <returns>Returns true on success.</returns>
  248. bool SetEnabled(CefMenuCommand commandId, bool enabled);
  249. /// <summary>
  250. /// Change the enabled status at the specified index.
  251. /// </summary>
  252. /// <param name="index">index</param>
  253. /// <param name="enabled">is enabled</param>
  254. /// <returns>Returns true on success.</returns>
  255. bool SetEnabledAt(int index, bool enabled);
  256. /// <summary>
  257. /// Returns true if the specified commandId is checked. Only applies to check and radio items.
  258. /// </summary>
  259. /// <param name="commandId">the command Id</param>
  260. /// <returns>Returns true if the specified commandId is checked. Only applies to check and radio items.</returns>
  261. bool IsChecked(CefMenuCommand commandId);
  262. /// <summary>
  263. /// Returns true if the specified index is checked. Only applies to check and radio items.
  264. /// </summary>
  265. /// <param name="index">index</param>
  266. /// <returns>Returns true if the specified index is checked. Only applies to check and radio items.</returns>
  267. bool IsCheckedAt(int index);
  268. /// <summary>
  269. /// Check the specified commandId. Only applies to check and radio items.
  270. /// </summary>
  271. /// <param name="commandId">the command Id</param>
  272. /// <param name="isChecked">set checked</param>
  273. /// <returns>Returns true on success.</returns>
  274. bool SetChecked(CefMenuCommand commandId, bool isChecked);
  275. /// <summary>
  276. /// Check the specified index. Only applies to check and radio items.
  277. /// </summary>
  278. /// <param name="index">index</param>
  279. /// <param name="isChecked">set checked</param>
  280. /// <returns>Returns true on success.</returns>
  281. bool SetCheckedAt(int index, bool isChecked);
  282. /// <summary>
  283. /// Returns true if the specified commandId has a keyboard accelerator assigned.
  284. /// </summary>
  285. /// <param name="commandId">the command Id</param>
  286. /// <returns>Returns true if the specified commandId has a keyboard accelerator assigned.</returns>
  287. bool HasAccelerator(CefMenuCommand commandId);
  288. /// <summary>
  289. /// Returns true if the specified index has a keyboard accelerator assigned.
  290. /// </summary>
  291. /// <param name="index">index</param>
  292. /// <returns>Returns true if the specified index has a keyboard accelerator assigned.</returns>
  293. bool HasAcceleratorAt(int index);
  294. /// <summary>
  295. /// Set the keyboard accelerator for the specified commandId.
  296. /// </summary>
  297. /// <param name="commandId">the command Id</param>
  298. /// <param name="keyCode">keyCode can be any key or character value. </param>
  299. /// <param name="shiftPressed">shift key pressed</param>
  300. /// <param name="ctrlPressed">ctrl key pressed</param>
  301. /// <param name="altPressed">alt key pressed</param>
  302. /// <returns>Returns true on success.</returns>
  303. bool SetAccelerator(CefMenuCommand commandId, int keyCode, bool shiftPressed, bool ctrlPressed, bool altPressed);
  304. /// <summary>
  305. /// Set the keyboard accelerator at the specified index. keyCode can be any key or character value.
  306. /// </summary>
  307. /// <param name="index">index</param>
  308. /// <param name="keyCode">keyCode can be any key or character value. </param>
  309. /// <param name="shiftPressed">shift key pressed</param>
  310. /// <param name="ctrlPressed">ctrl key pressed</param>
  311. /// <param name="altPressed">alt key pressed</param>
  312. /// <returns>Returns true on success.</returns>
  313. bool SetAcceleratorAt(int index, int keyCode, bool shiftPressed, bool ctrlPressed, bool altPressed);
  314. /// <summary>
  315. /// Remove the keyboard accelerator for the specified commandId.
  316. /// </summary>
  317. /// <param name="commandId">the command Id</param>
  318. /// <returns>Returns true on success.</returns>
  319. bool RemoveAccelerator(CefMenuCommand commandId);
  320. /// <summary>
  321. /// Remove the keyboard accelerator at the specified index.
  322. /// </summary>
  323. /// <param name="index">index</param>
  324. /// <returns>Returns true on success.</returns>
  325. bool RemoveAcceleratorAt(int index);
  326. /// <summary>
  327. /// Retrieves the keyboard accelerator for the specified commandId.
  328. /// </summary>
  329. /// <param name="commandId">the command Id</param>
  330. /// <param name="keyCode">keyCode can be any key or character value. </param>
  331. /// <param name="shiftPressed">shift key pressed</param>
  332. /// <param name="ctrlPressed">ctrl key pressed</param>
  333. /// <param name="altPressed">alt key pressed</param>
  334. /// <returns>Returns true on success.</returns>
  335. bool GetAccelerator(CefMenuCommand commandId, out int keyCode, out bool shiftPressed, out bool ctrlPressed, out bool altPressed);
  336. /// <summary>
  337. /// Retrieves the keyboard accelerator for the specified index.
  338. /// </summary>
  339. /// <param name="index">index</param>
  340. /// <param name="keyCode">keyCode can be any key or character value. </param>
  341. /// <param name="shiftPressed">shift key pressed</param>
  342. /// <param name="ctrlPressed">ctrl key pressed</param>
  343. /// <param name="altPressed">alt key pressed</param>
  344. /// <returns>Returns true on success.</returns>
  345. bool GetAcceleratorAt(int index, out int keyCode, out bool shiftPressed, out bool ctrlPressed, out bool altPressed);
  346. }
  347. }