Menu.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. menu_items = new MenuItemCollection (this);
  40. if (items != null)
  41. menu_items.AddRange (items);
  42. }
  43. #region Public Properties
  44. public IntPtr Handle {
  45. get {
  46. if (menu_handle == IntPtr.Zero) {
  47. menu_handle = CreateMenuHandle ();
  48. CreateItems ();
  49. }
  50. return menu_handle;
  51. }
  52. }
  53. public virtual bool IsParent {
  54. get {
  55. if (menu_items != null && menu_items.Count > 0)
  56. return true;
  57. else
  58. return false;
  59. }
  60. }
  61. public MenuItem MdiListItem {
  62. get {
  63. throw new NotImplementedException ();
  64. }
  65. }
  66. public MenuItemCollection MenuItems {
  67. get { return menu_items; }
  68. }
  69. #endregion Public Properties
  70. #region Public Methods
  71. protected void CloneMenu (Menu menuSrc)
  72. {
  73. throw new NotImplementedException ();
  74. }
  75. protected virtual IntPtr CreateMenuHandle ()
  76. {
  77. IntPtr menu;
  78. menu = MenuAPI.CreatePopupMenu ();
  79. Console.WriteLine ("Menu.CreateMenuHandle:" + menu);
  80. return menu;
  81. }
  82. protected override void Dispose (bool disposing)
  83. {
  84. if (disposing) {
  85. if (menu_handle != IntPtr.Zero)
  86. MenuAPI.DestroyMenu (menu_handle);
  87. }
  88. }
  89. public MenuItem FindMenuItem (int type, IntPtr value)
  90. {
  91. throw new NotImplementedException ();
  92. }
  93. protected int FindMergePosition (int mergeOrder)
  94. {
  95. throw new NotImplementedException ();
  96. }
  97. public ContextMenu GetContextMenu ()
  98. {
  99. throw new NotImplementedException ();
  100. }
  101. public MainMenu GetMainMenu ()
  102. {
  103. if (this is MainMenu)
  104. return (MainMenu) this;
  105. else
  106. return null;
  107. }
  108. public virtual void MergeMenu (Menu menuSrc)
  109. {
  110. throw new NotImplementedException ();
  111. }
  112. protected internal virtual bool ProcessCmdKey (ref Message msg, Keys keyData)
  113. {
  114. return false;
  115. }
  116. public override string ToString ()
  117. {
  118. return base.ToString ();
  119. }
  120. #endregion Public Methods
  121. #region Private Methods
  122. protected void CreateItems ()
  123. {
  124. Console.WriteLine ("Menu.CreateItems:" + menu_items.Count);
  125. for (int i = 0; i < menu_items.Count; i++)
  126. menu_items[i].Create ();
  127. Console.WriteLine ("End Menu.CreateItems:" + menu_items.Count);
  128. }
  129. #endregion Private Methods
  130. public class MenuItemCollection : IList, ICollection, IEnumerable
  131. {
  132. private Menu owner;
  133. private ArrayList items = new ArrayList ();
  134. public MenuItemCollection (Menu owner)
  135. {
  136. this.owner = owner;
  137. }
  138. #region Public Properties
  139. public virtual int Count {
  140. get { return items.Count;}
  141. }
  142. public virtual bool IsReadOnly {
  143. get { return false;}
  144. }
  145. bool ICollection.IsSynchronized {
  146. get { return false;}
  147. }
  148. object ICollection.SyncRoot {
  149. get { return this;}
  150. }
  151. bool IList.IsFixedSize {
  152. get { return false;}
  153. }
  154. public MenuItem this [int index] {
  155. get { return (MenuItem) items[index]; }
  156. }
  157. object IList.this[int index] {
  158. get { return items[index]; }
  159. set { items[index] = value; }
  160. }
  161. #endregion Public Properties
  162. #region Public Methods
  163. public virtual int Add (MenuItem mi)
  164. {
  165. mi.parent_menu = owner;
  166. items.Add (mi);
  167. return items.Count - 1;
  168. }
  169. public virtual MenuItem Add (string s)
  170. {
  171. throw new NotImplementedException ();
  172. }
  173. public virtual int Add (int index, MenuItem mi)
  174. {
  175. throw new NotImplementedException ();
  176. }
  177. public virtual MenuItem Add (string s, EventHandler e)
  178. {
  179. throw new NotImplementedException ();
  180. }
  181. public virtual MenuItem Add (string s, MenuItem[] items)
  182. {
  183. throw new NotImplementedException ();
  184. }
  185. public virtual void AddRange (MenuItem[] items)
  186. {
  187. if (items == null)
  188. throw new ArgumentNullException ("items");
  189. foreach (MenuItem mi in items)
  190. Add (mi);
  191. }
  192. public virtual void Clear ()
  193. {
  194. items.Clear ();
  195. }
  196. public bool Contains (MenuItem value)
  197. {
  198. return items.Contains (value);
  199. }
  200. public virtual void CopyTo (Array dest, int index)
  201. {
  202. throw new NotImplementedException ();
  203. }
  204. public virtual IEnumerator GetEnumerator ()
  205. {
  206. return items.GetEnumerator ();
  207. }
  208. int IList.Add (object value)
  209. {
  210. return Add ((MenuItem)value);
  211. }
  212. bool IList.Contains (object value)
  213. {
  214. return Contains ((MenuItem)value);
  215. }
  216. int IList.IndexOf (object value)
  217. {
  218. return IndexOf ((MenuItem)value);
  219. }
  220. void IList.Insert (int index, object value)
  221. {
  222. throw new NotImplementedException ();
  223. }
  224. void IList.Remove (object value)
  225. {
  226. throw new NotImplementedException ();
  227. }
  228. public int IndexOf (MenuItem value)
  229. {
  230. return items.IndexOf (value);
  231. }
  232. public virtual void Remove (MenuItem item)
  233. {
  234. throw new NotImplementedException ();
  235. }
  236. public virtual void RemoveAt (int index)
  237. {
  238. throw new NotImplementedException ();
  239. }
  240. #endregion Public Methods
  241. }
  242. }
  243. }