2007-01-01 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / MainMenu.cs
index 14612749fdb994bc63ecdb6db41ffd945a0fe500..db9f068c5b38bef7d4a84353a24a50550ff20b16 100644 (file)
@@ -47,8 +47,18 @@ namespace System.Windows.Forms
                        
                }
 
+#if NET_2_0
+               public MainMenu (IContainer container) : this ()
+               {
+                       container.Add (this);
+               }
+#endif
+
                #region Public Properties
                [Localizable(true)]
+#if NET_2_0
+               [AmbientValue (RightToLeft.Inherit)]
+#endif
                public virtual RightToLeft RightToLeft {
                        get { return right_to_left;}
                        set { right_to_left = value; }
@@ -65,6 +75,11 @@ namespace System.Windows.Forms
                        return new_menu;
                }
                
+               protected override IntPtr CreateMenuHandle ()
+               {                       
+                       return IntPtr.Zero;
+               }
+
                protected override void Dispose (bool disposing)
                {                       
                        base.Dispose (disposing);                       
@@ -84,25 +99,45 @@ namespace System.Windows.Forms
                
                #region Private Methods
 
-               internal void Draw ()           
-               {
+               internal void Draw () {
                        Draw (Rect);
                }
 
-               internal void Draw (Rectangle rect)
+               internal void Draw (Rectangle clip_rect) {
+                       PaintEventArgs pe;
+
+                       if (Wnd.IsHandleCreated) {
+                               pe = XplatUI.PaintEventStart(Wnd.window.Handle, false);
+                               pe.Graphics.Clip = new Region (clip_rect);
+                               Draw (pe, Rect);
+                               XplatUI.PaintEventEnd(Wnd.window.Handle, false);
+                       }
+               }
+
+               internal void Draw (PaintEventArgs pe)          
                {
-                       Graphics g;
+                       Draw (pe, Rect);
+               }
 
-                       if (Wnd.window.Handle == IntPtr.Zero)
+               internal void Draw (PaintEventArgs pe, Rectangle rect)
+               {
+                       if (!Wnd.IsHandleCreated)
                                return;
 
                        X = rect.X;
                        Y = rect.Y;
                        Height = Rect.Height;
 
-                       g = XplatUI.GetMenuDC(Wnd.window.Handle, IntPtr.Zero);
-                       ThemeEngine.Current.DrawMenuBar (g, this, rect);
-                       XplatUI.ReleaseMenuDC(Wnd.window.Handle, g);
+                       ThemeEngine.Current.DrawMenuBar (pe.Graphics, this, rect);
+
+                       PaintEventHandler eh = (PaintEventHandler)(Events [PaintEvent]);
+                       if (eh != null)
+                               eh (this, pe);
+               }
+
+               internal override void InvalidateItem (MenuItem item)
+               {
+                       Draw (item.bounds);
                }
                
                internal void SetForm (Form form)
@@ -120,13 +155,16 @@ namespace System.Windows.Forms
                        if (form == null)
                                return;
 
-                       Draw ();
+                       Rectangle clip = Rect;
+                       Height = 0; /* need this so the theme code will re-layout the menu items
+                                      (why is the theme code doing the layout?  argh) */
+                       Draw (clip);
                }
 
                /* Mouse events from the form */
                internal void OnMouseDown (object window, MouseEventArgs args)
                {                       
-                       tracker.OnClick (args);
+                       tracker.OnMouseDown (args);
                }
                
                internal void OnMouseMove (object window, MouseEventArgs e)
@@ -134,7 +172,14 @@ namespace System.Windows.Forms
                        MouseEventArgs args = new MouseEventArgs (e.Button, e.Clicks, Control.MousePosition.X, Control.MousePosition.Y, e.Delta);
                        tracker.OnMotion (args);
                }
-               
+
+               static object PaintEvent = new object ();
+
+               internal event PaintEventHandler Paint {
+                       add { Events.AddHandler (PaintEvent, value); }
+                       remove { Events.RemoveHandler (PaintEvent, value); }
+               }
+
                #endregion Private Methods
        }
 }