2 // System.Windows.Forms.Menu.MenuItem.cs
5 // stubbed out by Paul Osman (paul.osman@sympatico.ca)
6 // Dennis Hayes (dennish@raytek.com)
7 // Alexandre Pigolkine (pigolkine@gmx.de)
9 // (C) 2002/3 Ximian, Inc
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System
.Reflection
;
35 using System
.Globalization
;
36 //using System.Windows.Forms.AccessibleObject.IAccessible;
38 using System
.Runtime
.Remoting
;
39 using System
.ComponentModel
;
42 namespace System
.Windows
.Forms
{
48 public class MenuItem
: Menu
{
57 public MenuItem() : base(null) {
58 shortcut
= Shortcut
.None
;
59 mergeType
= MenuMerge
.Add
; // FIXME: what is default
64 public MenuItem(string s
) : this(){
68 public MenuItem(string s
, EventHandler e
) : this( s
) {
72 public MenuItem(string s
, MenuItem
[] items
) : base(items
) {
74 shortcut
= Shortcut
.None
;
75 mergeType
= MenuMerge
.Add
; // FIXME: what is default
79 public MenuItem(string s
, EventHandler e
, Shortcut sc
) : this(s
, e
) {
83 public MenuItem(MenuMerge mm
, int i
, Shortcut sc
, string s
, EventHandler e
, EventHandler e1
, EventHandler e2
, MenuItem
[] items
) : base(items
){
84 throw new NotImplementedException ();
91 public virtual MenuItem
CloneMenu() {
92 MenuItem result
= new MenuItem();
93 result
.CloneMenu(this);
97 //public override ObjRef CreateObjRef(Type t) {
98 // throw new NotImplementedException ();
101 //public override bool Equals(object o) {
102 // return base.Equals(o);
106 //public override int GetHashCode() {
107 // //FIXME add our proprities
108 // return base.GetHashCode();
111 public virtual MenuItem
MergeMenu() {
112 throw new NotImplementedException ();
115 public void MergeMenu(MenuItem m
) {
116 throw new NotImplementedException ();
119 public void PerformClick() {
120 OnClick( new EventArgs());
123 public virtual void PerformSelect() {
124 throw new NotImplementedException ();
127 public override string ToString() {
128 StringBuilder sb
= new StringBuilder();
129 sb
.Append(base.ToString());
130 sb
.AppendFormat(", Items.Count: {0}, Text: {1}", MenuItems
.Count
, Text
);
131 return sb
.ToString();
135 // -- Protected Methods
138 protected void CloneMenu(MenuItem m
) {
141 if( m
.MenuItems
.Count
!= 0){
142 MenuItem
[] all_items
= new MenuItem
[m
.MenuItems
.Count
];
143 m
.MenuItems
.CopyTo(all_items
, 0);
144 MenuItems
.AddRange(all_items
);
148 protected override void Dispose(bool disposing
){
149 base.Dispose(disposing
);
153 // //FIXME: free resources
154 // //throw new NotImplementedException ();
157 protected virtual void OnClick(EventArgs e
) {
163 protected virtual void OnDrawItem(DrawItemEventArgs e
) {
164 throw new NotImplementedException ();
167 protected virtual void OnMeasureItem(MeasureItemEventArgs e
) {
168 throw new NotImplementedException ();
171 protected virtual void OnPopUp(EventArgs e
) {
172 throw new NotImplementedException ();
175 protected virtual void OnSelect(EventArgs e
) {
176 throw new NotImplementedException ();
180 // -- Public Properties
182 private void ModifyParent()
186 Parent
.MenuStructureModified
= true;
190 private uint MenuItemFlags_
= (uint)MF_
.MF_ENABLED
| (uint)MF_
.MF_STRING
;
191 internal uint MenuItemFlags
195 return MenuItemFlags_
;
199 private bool GetPropertyByFlag( MF_ flag
)
201 return (MenuItemFlags_
& (uint)flag
) != 0 ? true : false;
204 private void SetPropertyByFlag( MF_ flag
, bool SetOrClear
)
206 uint PrevState
= MenuItemFlags_
;
209 MenuItemFlags_
|= (uint)flag
;
213 MenuItemFlags_
&= ~
(uint)flag
;
215 if( PrevState
!= MenuItemFlags_
)
219 public bool BarBreak
{
221 return GetPropertyByFlag(MF_
.MF_MENUBARBREAK
);
224 SetPropertyByFlag(MF_
.MF_MENUBARBREAK
, value);
231 return GetPropertyByFlag(MF_
.MF_MENUBREAK
);
234 SetPropertyByFlag(MF_
.MF_MENUBREAK
, value);
242 return GetPropertyByFlag(MF_
.MF_CHECKED
);
246 SetPropertyByFlag(MF_
.MF_CHECKED
, value);
250 //public IContainer Container {
252 // throw new NotImplementedException ();
256 public bool DefaultItem
{
259 return GetPropertyByFlag(MF_
.MF_DEFAULT
);
263 SetPropertyByFlag(MF_
.MF_DEFAULT
, value);
267 public bool Enabled
{
270 return !GetPropertyByFlag(MF_
.MF_DISABLED
| MF_
.MF_GRAYED
);
274 SetPropertyByFlag(MF_
.MF_DISABLED
| MF_
.MF_GRAYED
, !value);
278 // completely inherit from base class
279 public new IntPtr Handle {
281 throw new NotImplementedException ();
285 protected int index_
= -1;
287 internal void SetIndex( int value)
298 if( index_
!= value){
300 Parent
.MenuItems
.MoveItemToIndex(value, this);
301 Parent
.MenuStructureModified
= true;
307 public override bool IsParent
{
310 return base.IsParent
;
314 public bool MdiList
{
315 get { return mdiList; }
317 if ( mdiList
!= value ) {
318 MainMenu mainMenu
= GetMainMenu();
319 if ( mainMenu
!= null ) {
320 Form form
= mainMenu
.GetForm ( );
322 form
.replaceMdiWindowMenu ( value ? Handle
: IntPtr
.Zero
);
329 public int MergeOrder
{
338 public MenuMerge MergeType
{
347 public char Mnemonic
{
350 throw new NotImplementedException ();
354 public bool OwnerDraw
{
356 return GetPropertyByFlag(MF_
.MF_OWNERDRAW
);
359 SetPropertyByFlag(MF_
.MF_OWNERDRAW
, value);
363 internal void SetParent( Menu parent
) {
365 throw new System
.ArgumentNullException ("parent");
376 private bool RadioCheck_
= false;
377 public bool RadioCheck
{
388 public Shortcut Shortcut
{
397 public bool ShowShortcut
{
402 showShortcut
= value;
406 private string text_
= String
.Empty
;
415 SetPropertyByFlag(MF_
.MF_SEPARATOR
, true);
418 SetPropertyByFlag(MF_
.MF_SEPARATOR
, false);
419 //SetPropertyByFlag(MF_.MF_STRING, true);
426 private bool Visible_
= true;
427 public bool Visible
{
439 // -- Protected Properties
442 internal const int INVALID_MENU_ID
= -1; //0xffffffff;
443 protected int MenuID_
= INVALID_MENU_ID
;
445 // Provides unique id to all items in all menus, hopefully space is enougth.
446 // Possible to use array to keep ids from deleted menu items
448 protected static int MenuIDs_
= 1;
450 protected int GetNewMenuID() {
454 protected int MenuID
{
457 if( MenuID_
== INVALID_MENU_ID
) {
458 MenuID_
= GetNewMenuID();
465 // Btw, this function is funky, it is being used by routines that are supposed
466 // to be passing an IntPtr to the AppendMenu function
468 internal int GetID() {
476 public event EventHandler Click
;
478 //public event EventHandler Disposed;
479 public event DrawItemEventHandler DrawItem
;
480 public event MeasureItemEventHandler MeasureItem
;
481 public event EventHandler PopUp
;
482 public event EventHandler Select
;