ui/wpf/UIcore/Menu.cs

changeset 82
0cdb8089a29f
parent 81
5eb765a7a793
child 137
c9b8b9e0cfe8
equal deleted inserted replaced
81:5eb765a7a793 82:0cdb8089a29f
32 Menu menu = new Menu(label); 32 Menu menu = new Menu(label);
33 current.Last().Items.Add(menu); 33 current.Last().Items.Add(menu);
34 current.Add(menu); 34 current.Add(menu);
35 } 35 }
36 36
37 public void EndMenu() 37 public void EndSubMenu()
38 { 38 {
39 current.Remove(current.Last()); 39 current.Remove(current.Last());
40 } 40 }
41 41
42 public void AddMenuItem(String label, Action action) 42 public void AddMenuItem(String label, Action<IntPtr> action)
43 { 43 {
44 if(current.Count != 0) 44 if(current.Count != 0)
45 { 45 {
46 MenuItem item = new MenuItem(label, action); 46 MenuItem item = new MenuItem(label, action);
47 current.Last().Items.Add(item); 47 current.Last().Items.Add(item);
48 } 48 }
49 } 49 }
50 50
51 public System.Windows.Controls.Menu CreateMenu() 51 public System.Windows.Controls.Menu CreateMenu(IntPtr uiobj)
52 { 52 {
53 System.Windows.Controls.Menu menu = new System.Windows.Controls.Menu(); 53 System.Windows.Controls.Menu menu = new System.Windows.Controls.Menu();
54 foreach (Menu m in Menus) 54 foreach (Menu m in Menus)
55 { 55 {
56 System.Windows.Controls.MenuItem i = new System.Windows.Controls.MenuItem(); 56 System.Windows.Controls.MenuItem i = new System.Windows.Controls.MenuItem();
57 i.Header = m.Label; 57 i.Header = m.Label;
58 m.AddItems(i); 58 m.AddItems(i, uiobj);
59 menu.Items.Add(i); 59 menu.Items.Add(i);
60 } 60 }
61 return menu; 61 return menu;
62 } 62 }
63 } 63 }
64 64
65 public interface IMenuItem 65 public interface IMenuItem
66 { 66 {
67 void AddTo(System.Windows.Controls.MenuItem menu); 67 void AddTo(System.Windows.Controls.MenuItem menu, IntPtr uiobj);
68 } 68 }
69 69
70 public class Menu : IMenuItem 70 public class Menu : IMenuItem
71 { 71 {
72 public String Label; 72 public String Label;
75 public Menu(String label) 75 public Menu(String label)
76 { 76 {
77 Label = label; 77 Label = label;
78 } 78 }
79 79
80 public void AddItems(System.Windows.Controls.MenuItem i) 80 public void AddItems(System.Windows.Controls.MenuItem i, IntPtr uiobj)
81 { 81 {
82 foreach (IMenuItem item in Items) 82 foreach (IMenuItem item in Items)
83 { 83 {
84 item.AddTo(i); 84 item.AddTo(i, uiobj);
85 } 85 }
86 } 86 }
87 87
88 void IMenuItem.AddTo(System.Windows.Controls.MenuItem menu) 88 void IMenuItem.AddTo(System.Windows.Controls.MenuItem menu, IntPtr uiobj)
89 { 89 {
90 System.Windows.Controls.MenuItem i = new System.Windows.Controls.MenuItem(); 90 System.Windows.Controls.MenuItem i = new System.Windows.Controls.MenuItem();
91 i.Header = Label; 91 i.Header = Label;
92 AddItems(i); 92 AddItems(i, uiobj);
93 menu.Items.Add(i); 93 menu.Items.Add(i);
94 } 94 }
95 } 95 }
96 96
97 public class MenuItem : IMenuItem 97 public class MenuItem : IMenuItem
98 { 98 {
99 String Label; 99 String Label;
100 Action Action; 100 Action<IntPtr> Action;
101 101
102 public MenuItem(String label, Action action) 102 public MenuItem(String label, Action<IntPtr> action)
103 { 103 {
104 Label = label; 104 Label = label;
105 Action = action; 105 Action = action;
106 } 106 }
107 107
108 void IMenuItem.AddTo(System.Windows.Controls.MenuItem menu) 108 void IMenuItem.AddTo(System.Windows.Controls.MenuItem menu, IntPtr uiobj)
109 { 109 {
110 System.Windows.Controls.MenuItem i = new System.Windows.Controls.MenuItem(); 110 System.Windows.Controls.MenuItem i = new System.Windows.Controls.MenuItem();
111 EventCallback cb = new EventCallback(uiobj, Action);
112 i.Click += cb.Callback;
111 i.Header = Label; 113 i.Header = Label;
112 menu.Items.Add(i); 114 menu.Items.Add(i);
113 } 115 }
114 } 116 }
115 } 117 }

mercurial