Menu.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Jordi Mas i Hernandez, [email protected]
  24. //
  25. //
  26. // NOT COMPLETE
  27. using System.Collections;
  28. using System.ComponentModel;
  29. namespace System.Windows.Forms
  30. {
  31. public abstract class Menu : Component
  32. {
  33. protected MenuItemCollection menu_items;
  34. private IntPtr handle = IntPtr.Zero;
  35. public const int FindHandle = 0;
  36. public const int FindShortcut = 1;
  37. protected Menu (MenuItem[] items)
  38. {
  39. Console.WriteLine ("Menu.Menu " + (items != null));
  40. menu_items = new MenuItemCollection (this);
  41. if (items != null)
  42. menu_items.AddRange (items);
  43. }
  44. #region Public Properties
  45. public IntPtr Handle {
  46. get {
  47. if (handle == IntPtr.Zero) {
  48. handle = CreateMenuHandle ();
  49. CreateItems ();
  50. }
  51. return handle;
  52. }
  53. }
  54. public virtual bool IsParent {
  55. get {
  56. throw new NotImplementedException ();
  57. }
  58. }
  59. public MenuItem MdiListItem {
  60. get {
  61. throw new NotImplementedException ();
  62. }
  63. }
  64. public MenuItemCollection MenuItems {
  65. get { return menu_items; }
  66. }
  67. #endregion Public Properties
  68. #region Public Methods
  69. protected void CloneMenu (Menu menuSrc)
  70. {
  71. throw new NotImplementedException ();
  72. }
  73. protected virtual IntPtr CreateMenuHandle ()
  74. {
  75. IntPtr menu;
  76. menu = MenuAPI.CreatePopupMenu ();
  77. Console.WriteLine ("Menu.CreateMenuHandle:" + menu);
  78. return menu;
  79. }
  80. protected override void Dispose (bool diposing)
  81. {
  82. throw new NotImplementedException ();
  83. }
  84. public virtual void Dispose ()
  85. {
  86. throw new NotImplementedException ();
  87. }
  88. public MenuItem FindMenuItem (int type, IntPtr value)
  89. {
  90. throw new NotImplementedException ();
  91. }
  92. protected int FindMergePosition (int mergeOrder)
  93. {
  94. throw new NotImplementedException ();
  95. }
  96. public ContextMenu GetContextMenu ()
  97. {
  98. throw new NotImplementedException ();
  99. }
  100. public virtual void MergeMenu (Menu menuSrc)
  101. {
  102. throw new NotImplementedException ();
  103. }
  104. protected internal virtual bool ProcessCmdKey (ref Message msg, Keys keyData)
  105. {
  106. throw new NotImplementedException ();
  107. }
  108. public override string ToString ()
  109. {
  110. throw new NotImplementedException ();
  111. }
  112. #endregion Public Methods
  113. #region Private Methods
  114. private void CreateItems ()
  115. {
  116. Console.WriteLine ("Menu.CreateItems:" + menu_items.Count);
  117. for (int i = 0; i < menu_items.Count; i++)
  118. menu_items[i].Create ();
  119. }
  120. #endregion Private Methods
  121. public class MenuItemCollection : IList, ICollection, IEnumerable
  122. {
  123. private Menu owner;
  124. private ArrayList items = new ArrayList ();
  125. public MenuItemCollection (Menu owner)
  126. {
  127. this.owner = owner;
  128. }
  129. #region Public Properties
  130. public virtual int Count {
  131. get { return items.Count;}
  132. }
  133. public virtual bool IsReadOnly {
  134. get { return false;}
  135. }
  136. bool ICollection.IsSynchronized {
  137. get { return false;}
  138. }
  139. object ICollection.SyncRoot {
  140. get { return this;}
  141. }
  142. bool IList.IsFixedSize {
  143. get { return false;}
  144. }
  145. public MenuItem this [int index] {
  146. get { return (MenuItem) items[index]; }
  147. }
  148. object IList.this[int index] {
  149. get { return items[index]; }
  150. set { items[index] = value; }
  151. }
  152. #endregion Public Properties
  153. #region Public Methods
  154. public virtual int Add (MenuItem mi)
  155. {
  156. mi.parent_menu = owner;
  157. items.Add (mi);
  158. return items.Count - 1;
  159. }
  160. public virtual MenuItem Add (string s)
  161. {
  162. throw new NotImplementedException ();
  163. }
  164. public virtual int Add (int index, MenuItem mi)
  165. {
  166. throw new NotImplementedException ();
  167. }
  168. public virtual MenuItem Add (string s, EventHandler e)
  169. {
  170. throw new NotImplementedException ();
  171. }
  172. public virtual MenuItem Add (string s, MenuItem[] items)
  173. {
  174. throw new NotImplementedException ();
  175. }
  176. public virtual void AddRange (MenuItem[] items)
  177. {
  178. if (items == null)
  179. throw new ArgumentNullException ("items");
  180. foreach (MenuItem mi in items)
  181. Add (mi);
  182. }
  183. public virtual void Clear ()
  184. {
  185. items.Clear ();
  186. }
  187. public bool Contains (MenuItem value)
  188. {
  189. throw new NotImplementedException ();
  190. }
  191. public virtual void CopyTo (Array dest, int index)
  192. {
  193. throw new NotImplementedException ();
  194. }
  195. public virtual IEnumerator GetEnumerator ()
  196. {
  197. throw new NotImplementedException ();
  198. }
  199. int IList.Add (object value)
  200. {
  201. throw new NotImplementedException ();
  202. }
  203. bool IList.Contains (object value)
  204. {
  205. throw new NotImplementedException ();
  206. }
  207. int IList.IndexOf (object value)
  208. {
  209. throw new NotImplementedException ();
  210. }
  211. void IList.Insert (int index, object value)
  212. {
  213. throw new NotImplementedException ();
  214. }
  215. void IList.Remove (object value)
  216. {
  217. throw new NotImplementedException ();
  218. }
  219. public int IndexOf (MenuItem value)
  220. {
  221. throw new NotImplementedException ();
  222. }
  223. public virtual void Remove (MenuItem item)
  224. {
  225. throw new NotImplementedException ();
  226. }
  227. public virtual void RemoveAt (int index)
  228. {
  229. throw new NotImplementedException ();
  230. }
  231. #endregion Public Methods
  232. }
  233. }
  234. }