Menu.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. internal MenuItemCollection menu_items;
  34. internal IntPtr menu_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 (menu_handle == IntPtr.Zero) {
  48. menu_handle = CreateMenuHandle ();
  49. CreateItems ();
  50. }
  51. return menu_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 MenuItem FindMenuItem (int type, IntPtr value)
  85. {
  86. throw new NotImplementedException ();
  87. }
  88. protected int FindMergePosition (int mergeOrder)
  89. {
  90. throw new NotImplementedException ();
  91. }
  92. public ContextMenu GetContextMenu ()
  93. {
  94. throw new NotImplementedException ();
  95. }
  96. public MainMenu GetMainMenu ()
  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. protected 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. Console.WriteLine ("End Menu.CreateItems:" + menu_items.Count);
  120. }
  121. #endregion Private Methods
  122. public class MenuItemCollection : IList, ICollection, IEnumerable
  123. {
  124. private Menu owner;
  125. private ArrayList items = new ArrayList ();
  126. public MenuItemCollection (Menu owner)
  127. {
  128. this.owner = owner;
  129. }
  130. #region Public Properties
  131. public virtual int Count {
  132. get { return items.Count;}
  133. }
  134. public virtual bool IsReadOnly {
  135. get { return false;}
  136. }
  137. bool ICollection.IsSynchronized {
  138. get { return false;}
  139. }
  140. object ICollection.SyncRoot {
  141. get { return this;}
  142. }
  143. bool IList.IsFixedSize {
  144. get { return false;}
  145. }
  146. public MenuItem this [int index] {
  147. get { return (MenuItem) items[index]; }
  148. }
  149. object IList.this[int index] {
  150. get { return items[index]; }
  151. set { items[index] = value; }
  152. }
  153. #endregion Public Properties
  154. #region Public Methods
  155. public virtual int Add (MenuItem mi)
  156. {
  157. mi.parent_menu = owner;
  158. items.Add (mi);
  159. return items.Count - 1;
  160. }
  161. public virtual MenuItem Add (string s)
  162. {
  163. throw new NotImplementedException ();
  164. }
  165. public virtual int Add (int index, MenuItem mi)
  166. {
  167. throw new NotImplementedException ();
  168. }
  169. public virtual MenuItem Add (string s, EventHandler e)
  170. {
  171. throw new NotImplementedException ();
  172. }
  173. public virtual MenuItem Add (string s, MenuItem[] items)
  174. {
  175. throw new NotImplementedException ();
  176. }
  177. public virtual void AddRange (MenuItem[] items)
  178. {
  179. if (items == null)
  180. throw new ArgumentNullException ("items");
  181. foreach (MenuItem mi in items)
  182. Add (mi);
  183. }
  184. public virtual void Clear ()
  185. {
  186. items.Clear ();
  187. }
  188. public bool Contains (MenuItem value)
  189. {
  190. throw new NotImplementedException ();
  191. }
  192. public virtual void CopyTo (Array dest, int index)
  193. {
  194. throw new NotImplementedException ();
  195. }
  196. public virtual IEnumerator GetEnumerator ()
  197. {
  198. throw new NotImplementedException ();
  199. }
  200. int IList.Add (object value)
  201. {
  202. throw new NotImplementedException ();
  203. }
  204. bool IList.Contains (object value)
  205. {
  206. throw new NotImplementedException ();
  207. }
  208. int IList.IndexOf (object value)
  209. {
  210. throw new NotImplementedException ();
  211. }
  212. void IList.Insert (int index, object value)
  213. {
  214. throw new NotImplementedException ();
  215. }
  216. void IList.Remove (object value)
  217. {
  218. throw new NotImplementedException ();
  219. }
  220. public int IndexOf (MenuItem value)
  221. {
  222. throw new NotImplementedException ();
  223. }
  224. public virtual void Remove (MenuItem item)
  225. {
  226. throw new NotImplementedException ();
  227. }
  228. public virtual void RemoveAt (int index)
  229. {
  230. throw new NotImplementedException ();
  231. }
  232. #endregion Public Methods
  233. }
  234. }
  235. }