(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Windows.Forms / System.Windows.Forms.Test / MenuTest.cs
blob3ad19009f57a0d7cdd0b1f2a328bd8f415d68b18
1 using System;
2 using System.Drawing;
3 using System.Windows.Forms;
4 using System.Collections;
5 using System.Runtime.InteropServices;
7 class MyMenuItem : MenuItem
9 public MyMenuItem( string s) : base(s)
13 public int GetID()
15 return MenuID;
18 public new IntPtr Handle
20 get
22 return IntPtr.Zero;
28 // Test basic functionality of the Application and Form class
29 class MenuTest : Form
32 Button button;
33 MainMenu testMenu_ = null;
35 public MenuTest () : base ()
37 ClientSize = new Size(300, 250);
38 CreateMyMainMenu();
39 button = new Button ();
41 button.Top = 20;
42 button.Left = 20;
43 button.Width = 50;
44 button.Height = 50;
45 //button.Parent = this;
46 button.Text = "Click Me!";
48 button.Click += new EventHandler(OnMenuButtonClick);
49 this.Controls.AddRange(new System.Windows.Forms.Control[] {button});
53 MenuItem[] RecentFilesMenu()
55 MenuItem menuItem1 = new MenuItem("MenuTest.cs");
56 MenuItem menuItem2 = new MenuItem("/etc/passwd");
57 MenuItem menuItem3 = new MenuItem("~/.wine/config");
58 return new MenuItem[3] {menuItem1, menuItem2, menuItem3};
61 // Doesn't gets called, waiting for Button implementation
62 void OnMenuButtonClick( object c, EventArgs e)
64 if( Menu != null)
66 Menu = null;
68 else
70 Menu = testMenu_;
74 MenuItem menuItem4 = null;
76 public void CreateMyMainMenu()
78 testMenu_ = new MainMenu();
80 MyMenuItem myMI = new MyMenuItem("2");
81 MenuItem refMi = myMI;
82 IntPtr ip = refMi.Handle;
83 ip = myMI.Handle;
84 System.Console.WriteLine("My menu ID {0}", myMI.GetID());
86 MenuItem menuItem1 = new MenuItem("&New", new System.EventHandler(this.OnFileNew));
87 MenuItem menuItem2 = new MenuItem("&Open...", new System.EventHandler(this.OnFileOpen));
88 MenuItem menuItem3 = new MenuItem("&Quit", new System.EventHandler(this.OnFileQuit));
89 MenuItem menuItem4 = new MenuItem("Test &Controls", new System.EventHandler(this.OnTestControlMethods));
90 MenuItem recentFiles = new MenuItem("Recent files", RecentFilesMenu());
91 MenuItem FileMenu = new MenuItem("File", new MenuItem[]{menuItem1, menuItem2,recentFiles, menuItem3, menuItem4});
93 myMI = new MyMenuItem("2");
94 System.Console.WriteLine("My menu ID {0}", myMI.GetID());
96 menuItem1.Text = "&File";
97 menuItem2.Text = "&Edit";
98 menuItem3.Text = "E&xit";
100 MenuItem mi10 = new MenuItem("Dos");
101 MenuItem mi11 = new MenuItem("Unix");
102 menuItem4 = new MenuItem("&Save As...", new MenuItem[]{mi10, mi11});
103 FileMenu.MenuItems.Add(2, menuItem4);
104 int pos = testMenu_.MenuItems.Add(FileMenu);
105 System.Console.WriteLine("Menu File added at position {0}", pos);
107 MenuItem menuTest1 = new MenuItem("&Test properties", new System.EventHandler(this.OnTestProperties));
108 MenuItem TestMenu = new MenuItem("Test", new MenuItem[]{menuTest1});
109 testMenu_.MenuItems.Add(TestMenu);
111 Menu = testMenu_;
113 myMI = new MyMenuItem("2");
114 System.Console.WriteLine("My menu ID {0}", myMI.GetID());
117 protected void OnFileNew( object sender, System.EventArgs e)
119 MessageBox.Show(this, "The File->New command selected", "MenuTest");
120 menuItem4.Click += new System.EventHandler( this.OnFileSaveAs);
121 menuItem4.MenuItems.Clear();
124 protected void OnFileOpen( object sender, System.EventArgs e)
126 MessageBox.Show(this, "A file-open dialog will appear soon", "MenuTest");
129 protected void OnFileQuit( object sender, System.EventArgs e)
131 System.Console.WriteLine("The Exit command selected");
132 Application.Exit();
135 protected void OnFileSaveAs( object sender, System.EventArgs e)
137 MessageBox.Show("OnFileSaveAs");
138 menuItem4.Index = 0;
141 protected void OnTestProperties( object sender, System.EventArgs e)
143 MenuItem send = sender as MenuItem;
144 if( send != null)
146 Menu parent = send.Parent;
147 if( parent != null){
148 MenuItem mi1 = new MenuItem("BarBreak");
149 mi1.BarBreak = true;
150 MenuItem mi2 = new MenuItem("Break");
151 mi2.Break = true;
152 MenuItem mi3 = new MenuItem("Checked");
153 mi3.Checked = true;
154 MenuItem mi4 = new MenuItem("Disabled");
155 mi4.Enabled = false;
156 MenuItem mi5 = new MenuItem("DefaultItem");
157 mi5.DefaultItem = true;
158 MenuItem mi6 = new MenuItem("RadioCheck");
159 mi6.RadioCheck = true;
160 mi6.Checked = true;
161 MenuItem mi7 = new MenuItem("-");
162 mi7.RadioCheck = true;
164 MenuItem SubMenu = new MenuItem("SubMenu", new MenuItem[]{mi1, mi2, mi3, mi4, mi5, mi6, mi7});
165 parent.MenuItems.Add(SubMenu);
170 [DllImport ("user32.dll",
171 CallingConvention = CallingConvention.StdCall,
172 CharSet = CharSet.Ansi, EntryPoint = "CreateWindowExA")]
173 internal static extern IntPtr CreateWindowExEx (
174 uint dwExStyle, string lpClassName,
175 string lpWindowName, uint dwStyle,
176 int x, int y, int nWidth, int nHeight,
177 IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance,
178 ref object lpParam);
180 protected void OnTestControlMethods( object sender, System.EventArgs e)
182 int WS_CHILD = 0x40000000;
183 int WS_VISIBLE = 0x10000000;
184 object abc = null;
185 IntPtr hwnd = CreateWindowExEx(0, "BUTTON", "WindowName",
186 (uint)( WS_CHILD | WS_VISIBLE), 10, 10,
187 100, 50, Handle, (IntPtr)100, (IntPtr)0, ref abc);
189 Control cc = Control.FromChildHandle(hwnd);
190 if( cc == this) {
191 Console.WriteLine("FromChildHandle: The frame was found by BUTTON");
193 else if( cc == null) {
194 Console.WriteLine("FromChildHandle: Nothing was found by BUTTON");
196 else {
197 Console.WriteLine("FromChildHandle: Some control was found by BUTTON");
200 Control c1 = Control.FromHandle(hwnd);
201 if( c1 == this) {
202 Console.WriteLine("FromHandle: The frame was found by BUTTON");
204 else if( c1 == null) {
205 Console.WriteLine("FromHandle: Nothing was found by BUTTON");
207 else {
208 Console.WriteLine("FromHandle: Some control was found by BUTTON");
211 Control cntr = Control.FromChildHandle(button.Handle);
212 if( cntr == button) {
213 Console.WriteLine("FromChildHandle are the same");
215 else {
216 Console.WriteLine("FromChildHandle are NOT the same");
218 cntr = Control.FromHandle(button.Handle);
219 if( cntr == button) {
220 Console.WriteLine("FromHandle are the same");
222 else {
223 Console.WriteLine("FromHandle are NOT the same");
227 // - verifies the WndProc can be overridden propery
228 // - verifies the Application.MessageLoop is working properly
229 protected override void WndProc (ref Message m)
231 base.WndProc (ref m);
233 // should be true after the Run command is reached
234 //Console.WriteLine ("Application.MessageLoop: " +
235 //Application.MessageLoop);
238 static public void Test1 ()
240 MenuTest form = new MenuTest ();
242 //should be false
243 Console.WriteLine ("Application.MessageLoop: " +
244 Application.MessageLoop);
246 Application.Run (form);
249 static public void Test2()
251 MenuItem mi = new MyMenuItem("123");
252 MenuItem mp = new MenuItem("PPP", new MenuItem[] { mi });
253 MenuItem mc = mi.CloneMenu();
255 System.Console.WriteLine("Clone equals to original {0}", mc.Equals(mi));
256 System.Console.WriteLine("Original Parent {0}", mi.Parent.ToString());
257 System.Console.WriteLine("Clone Parent {0}", mc.Parent != null ? mc.Parent.ToString() : "<null>");
258 System.Console.WriteLine("Clone Parent is the same {0}", mc.Parent == mi.Parent);
261 static public void Test3()
263 MenuItem mi1 = new MenuItem("123");
264 MenuItem mi2 = new MenuItem("234");
266 MenuItem parent = new MenuItem( "parent", new MenuItem[] { mi1, mi2});
267 IList il = (IList)parent.MenuItems;
268 System.Console.WriteLine("List of menu items IsReadOnly {0}, IsFixedSize {1}", il.IsReadOnly, il.IsFixedSize);
269 il.Add(new MenuItem("This must be inside"));
270 //il.Add( new ArrayList());
271 //il[1] = new MenuItem("345");
272 //parent.MenuItems[1] = new MenuItem("asd");
275 static public int Main (String[] args)
277 Test3();
278 Test2();
279 Test1();
280 return 0;