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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2004-2005 Novell, Inc.
23 // Jordi Mas i Hernandez, jordi@ximian.com
27 using System.ComponentModel;
28 using System.ComponentModel.Design;
31 namespace System.Windows.Forms
33 [DefaultEvent("Popup")]
34 public class ContextMenu : Menu
36 private RightToLeft right_to_left;
37 private Control src_control;
41 static object CollapseEvent = new object ();
43 static object PopupEvent = new object ();
46 public event EventHandler Collapse {
47 add { Events.AddHandler (CollapseEvent, value); }
48 remove { Events.RemoveHandler (CollapseEvent, value); }
52 public event EventHandler Popup {
53 add { Events.AddHandler (PopupEvent, value); }
54 remove { Events.RemoveHandler (PopupEvent, value); }
59 public ContextMenu () : base (null)
61 right_to_left = RightToLeft.Inherit;
64 public ContextMenu (MenuItem [] menuItems) : base (menuItems)
66 right_to_left = RightToLeft.Inherit;
69 #region Public Properties
73 [DefaultValue (RightToLeft.No)]
75 public virtual RightToLeft RightToLeft {
76 get { return right_to_left; }
77 set { right_to_left = value; }
81 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
82 public Control SourceControl {
83 get { return src_control; }
86 #endregion Public Properties
88 #region Public Methods
91 protected internal virtual bool ProcessCmdKey (ref Message msg, Keys keyData, Control control)
93 src_control = control;
94 return ProcessCmdKey (ref msg, keyData);
97 protected internal virtual void OnCollapse (EventArgs e)
99 EventHandler eh = (EventHandler) (Events [CollapseEvent]);
105 protected internal virtual void OnPopup (EventArgs e)
107 EventHandler eh = (EventHandler) (Events [PopupEvent]);
112 public void Show (Control control, Point pos)
115 throw new ArgumentException ();
117 src_control = control;
119 OnPopup (EventArgs.Empty);
120 pos = control.PointToScreen (pos);
121 MenuTracker.TrackPopupMenu (this, pos);
123 OnCollapse (EventArgs.Empty);
128 public void Show (Control control, Point pos, LeftRightAlignment alignment)
132 if (alignment == LeftRightAlignment.Left)
133 point = new Point ((pos.X - control.Width), pos.Y);
137 Show (control, point);
140 #endregion Public Methods