2007-01-01 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / MainMenu.cs
index 39cdd6409eae7534683ff7eddbf5c4f15fad036e..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; }
@@ -90,10 +100,15 @@ namespace System.Windows.Forms
                #region Private Methods
 
                internal void Draw () {
+                       Draw (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);
                        }
@@ -115,8 +130,14 @@ namespace System.Windows.Forms
 
                        ThemeEngine.Current.DrawMenuBar (pe.Graphics, this, rect);
 
-                       if (Paint != null)
-                               Paint (this, pe);
+                       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)
@@ -134,15 +155,16 @@ namespace System.Windows.Forms
                        if (form == null)
                                return;
 
-                       Height = 0;
-
-                       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)
@@ -151,7 +173,12 @@ namespace System.Windows.Forms
                        tracker.OnMotion (args);
                }
 
-               internal event PaintEventHandler Paint;
+               static object PaintEvent = new object ();
+
+               internal event PaintEventHandler Paint {
+                       add { Events.AddHandler (PaintEvent, value); }
+                       remove { Events.RemoveHandler (PaintEvent, value); }
+               }
 
                #endregion Private Methods
        }