* TreeView.cs: Don't draw the selected node when we lose
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / MainMenu.cs
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-2005 Novell, Inc.
21 //
22 // Authors:
23 //      Jordi Mas i Hernandez, jordi@ximian.com
24 //
25 //
26
27 // COMPLETE
28
29 using System.ComponentModel;
30
31 namespace System.Windows.Forms
32 {
33         [ToolboxItemFilter("System.Windows.Forms.MainMenu", ToolboxItemFilterType.Allow)]
34         public class MainMenu : Menu
35         {
36                 private RightToLeft right_to_left = RightToLeft.Inherit;
37                 private Form form = null;
38                 private MenuAPI.TRACKER tracker = null;
39
40                 public MainMenu () : base (null)
41                 {
42                         
43                 }
44
45                 public MainMenu (MenuItem[] items) : base (items)
46                 {
47                         
48                 }
49
50                 #region Public Properties
51                 [Localizable(true)]
52                 public virtual RightToLeft RightToLeft {
53                         get { return right_to_left;}
54                         set { right_to_left = value; }
55                 }
56
57                 #endregion Public Properties
58
59                 #region Public Methods
60                         
61                 public virtual MainMenu CloneMenu ()
62                 {
63                         MainMenu new_menu = new MainMenu ();
64                         new_menu.CloneMenu (this);
65                         return new_menu;
66                 }
67                 
68                 protected override IntPtr CreateMenuHandle ()
69                 {                               
70                         return MenuAPI.CreateMenu (this);                                               
71                 }
72
73                 protected void Dispose (bool disposing)
74                 {                       
75                         base.Dispose (disposing);                       
76                 }
77
78                 public Form GetForm ()
79                 {
80                         return form;
81                 }
82
83                 public override string ToString ()
84                 {
85                         return base.ToString () + ", GetForm: " + form;
86                 }
87
88                 #endregion Public Methods
89                 
90                 #region Private Methods
91                 
92                 internal void SetForm (Form form)
93                 {
94                         this.form = form;
95                         
96                         if (tracker == null) {
97                                 tracker = new MenuAPI.TRACKER (); 
98                                 tracker.hCurrentMenu = tracker.hTopMenu = Handle;
99                         }
100                 }
101                 
102                 internal override void MenuChanged ()
103                 {
104                         base.MenuChanged ();
105                         tracker = new MenuAPI.TRACKER (); 
106                         tracker.hCurrentMenu = tracker.hTopMenu = menu_handle;
107
108                         MenuAPI.SetMenuBarWindow (menu_handle, form);
109                         // TODO: Need to invalidate & redraw topmenu
110                 }
111
112
113                 /* Mouse events from the form */
114                 internal void OnMouseDown (Form window, MouseEventArgs e)
115                 {                       
116                         MenuAPI.TrackBarMouseEvent (Handle, window, e, MenuAPI.MenuMouseEvent.Down, tracker);
117                 }
118                 
119                 internal void OnMouseMove (Form window, MouseEventArgs e)
120                 {                       
121                         MouseEventArgs ev = new MouseEventArgs (e.Button, e.Clicks, Control.MousePosition.X, Control.MousePosition.Y, e.Delta);
122                         MenuAPI.TrackBarMouseEvent (Handle, window, ev, MenuAPI.MenuMouseEvent.Move, tracker);
123                 }
124                 
125                 #endregion Private Methods
126         }
127 }
128
129