2005-11-23 Mike Kestner <mkestner@novell.com>
[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 using System.Drawing;
31
32 namespace System.Windows.Forms
33 {
34         [ToolboxItemFilter("System.Windows.Forms.MainMenu", ToolboxItemFilterType.Allow)]
35         public class MainMenu : Menu
36         {
37                 private RightToLeft right_to_left = RightToLeft.Inherit;
38                 private Form form = null;
39                 internal MenuTracker tracker = null;
40
41                 public MainMenu () : base (null)
42                 {
43                         
44                 }
45
46                 public MainMenu (MenuItem[] items) : base (items)
47                 {
48                         
49                 }
50
51                 #region Public Properties
52                 [Localizable(true)]
53                 public virtual RightToLeft RightToLeft {
54                         get { return right_to_left;}
55                         set { right_to_left = value; }
56                 }
57
58                 #endregion Public Properties
59
60                 #region Public Methods
61                         
62                 public virtual MainMenu CloneMenu ()
63                 {
64                         MainMenu new_menu = new MainMenu ();
65                         new_menu.CloneMenu (this);
66                         return new_menu;
67                 }
68                 
69                 protected override void Dispose (bool disposing)
70                 {                       
71                         base.Dispose (disposing);                       
72                 }
73
74                 public Form GetForm ()
75                 {
76                         return form;
77                 }
78
79                 public override string ToString ()
80                 {
81                         return base.ToString () + ", GetForm: " + form;
82                 }
83
84                 #endregion Public Methods
85                 
86                 #region Private Methods
87
88                 internal void Draw ()           
89                 {
90                         Draw (Rect);
91                 }
92
93                 internal void Draw (Rectangle rect)
94                 {
95                         Graphics g;
96
97                         if (Wnd.window.Handle == IntPtr.Zero)
98                                 return;
99
100                         X = rect.X;
101                         Y = rect.Y;
102                         Height = Rect.Height;
103
104                         g = XplatUI.GetMenuDC(Wnd.window.Handle, IntPtr.Zero);
105                         ThemeEngine.Current.DrawMenuBar (g, this, rect);
106                         XplatUI.ReleaseMenuDC(Wnd.window.Handle, g);
107                 }
108                 
109                 internal void SetForm (Form form)
110                 {
111                         this.form = form;
112                         Wnd = form;
113                         
114                         if (tracker == null)
115                                 tracker = new MenuTracker (this); 
116                 }
117                 
118                 internal override void MenuChanged ()
119                 {
120                         base.MenuChanged ();
121                         if (form == null)
122                                 return;
123
124                         Draw ();
125                 }
126
127                 /* Mouse events from the form */
128                 internal void OnMouseDown (object window, MouseEventArgs args)
129                 {                       
130                         tracker.OnClick (args);
131                 }
132                 
133                 internal void OnMouseMove (object window, MouseEventArgs e)
134                 {                       
135                         MouseEventArgs args = new MouseEventArgs (e.Button, e.Clicks, Control.MousePosition.X, Control.MousePosition.Y, e.Delta);
136                         tracker.OnMotion (args);
137                 }
138                 
139                 #endregion Private Methods
140         }
141 }
142
143