Menu.cs :  » GUI » wx-NET » wx » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » wx NET 
wx NET » wx » Menu.cs
//-----------------------------------------------------------------------------
// wx.NET - Menu.cs
//
// The wxMenu wrapper class.
//
// Written by Jason Perkins (jason@379.com)
// (C) 2003 by 379, Inc.
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: Menu.cs,v 1.18 2007/11/24 17:55:45 harald_meyer Exp $
//-----------------------------------------------------------------------------

using System;
using System.Collections;
using System.Runtime.InteropServices;

namespace wx{
  public class MenuBase : EvtHandler
  {
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_ctor1(IntPtr titel, uint style);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_ctor2(uint style);
    
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_Append(IntPtr self, int id, IntPtr item, IntPtr help, ItemKind kind);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_AppendSubMenu(IntPtr self, int id, IntPtr item, IntPtr subMenu, IntPtr help);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_AppendItem(IntPtr self, IntPtr item);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_AppendSeparator(IntPtr self);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_AppendCheckItem(IntPtr self, int itemid, IntPtr text, IntPtr help);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_AppendRadioItem(IntPtr self, int itemid, IntPtr text, IntPtr help);
    [DllImport("wx-c")] static extern int    wxMenuBase_GetMenuItemCount(IntPtr self);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_GetMenuItem(IntPtr self, int index);
    [DllImport("wx-c")] static extern void   wxMenuBase_Break(IntPtr self);
    
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_Insert(IntPtr self, int pos, IntPtr item);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_Insert2(IntPtr self, int pos, int itemid, IntPtr text, IntPtr help, ItemKind kind);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_InsertSeparator(IntPtr self, int pos);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_InsertCheckItem(IntPtr self, int pos, int itemid, IntPtr text, IntPtr help);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_InsertRadioItem(IntPtr self, int pos, int itemid, IntPtr text, IntPtr help);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_InsertSubMenu(IntPtr self, int pos, int itemid, IntPtr text, IntPtr submenu, IntPtr help);
    
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_Prepend(IntPtr self, IntPtr item);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_Prepend2(IntPtr self, int itemid, IntPtr text, IntPtr help, ItemKind kind);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_PrependSeparator(IntPtr self);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_PrependCheckItem(IntPtr self, int itemid, IntPtr text, IntPtr help);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_PrependRadioItem(IntPtr self, int itemid, IntPtr text, IntPtr help);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_PrependSubMenu(IntPtr self, int itemid, IntPtr text, IntPtr submenu, IntPtr help);
    
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_Remove(IntPtr self, int itemid);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_Remove2(IntPtr self, IntPtr item);
    
    [DllImport("wx-c")] static extern bool   wxMenuBase_Delete(IntPtr self, int itemid);
    [DllImport("wx-c")] static extern bool   wxMenuBase_Delete2(IntPtr self, IntPtr item);
    
    [DllImport("wx-c")] static extern bool   wxMenuBase_Destroy(IntPtr self, int itemid);
    [DllImport("wx-c")] static extern bool   wxMenuBase_Destroy2(IntPtr self, IntPtr item);
    
    [DllImport("wx-c")] static extern int    wxMenuBase_FindItem(IntPtr self, IntPtr item);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_FindItem2(IntPtr self, int itemid, ref IntPtr menu); 
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_FindItemByPosition(IntPtr self, int position);
    
    [DllImport("wx-c")] static extern void   wxMenuBase_Enable(IntPtr self, int itemid, bool enable);
    [DllImport("wx-c")] static extern bool   wxMenuBase_IsEnabled(IntPtr self, int itemid);
    
    [DllImport("wx-c")] static extern void   wxMenuBase_Check(IntPtr self, int id, bool check);
    [DllImport("wx-c")] static extern bool   wxMenuBase_IsChecked(IntPtr self, int itemid);
    
    [DllImport("wx-c")] static extern void   wxMenuBase_SetLabel(IntPtr self, int itemid, IntPtr label);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_GetLabel(IntPtr self, int itemid);
    
    [DllImport("wx-c")] static extern void   wxMenuBase_SetHelpString(IntPtr self, int itemid, IntPtr helpString);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_GetHelpString(IntPtr self, int itemid);    
    
    [DllImport("wx-c")] static extern void   wxMenuBase_SetTitle(IntPtr self, IntPtr title);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_GetTitle(IntPtr self);    
    
    [DllImport("wx-c")] static extern void   wxMenuBase_SetInvokingWindow(IntPtr self, IntPtr win);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_GetInvokingWindow(IntPtr self);
    
    [DllImport("wx-c")] static extern uint  wxMenuBase_GetStyle(IntPtr self);
    
    [DllImport("wx-c")] static extern void   wxMenuBase_SetEventHandler(IntPtr self, IntPtr handler);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_GetEventHandler(IntPtr self);
    
    [DllImport("wx-c")] static extern void   wxMenuBase_UpdateUI(IntPtr self, IntPtr source);
    
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_GetMenuBar(IntPtr self);
    
    [DllImport("wx-c")] static extern bool   wxMenuBase_IsAttached(IntPtr self);
    
    [DllImport("wx-c")] static extern void   wxMenuBase_SetParent(IntPtr self, IntPtr parent);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_GetParent(IntPtr self);
    
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_FindChildItem(IntPtr self, int itemid, out int pos);
    [DllImport("wx-c")] static extern IntPtr wxMenuBase_FindChildItem2(IntPtr self, int itemid);
    [DllImport("wx-c")] static extern bool   wxMenuBase_SendEvent(IntPtr self, int itemid, int xchecked);
  
    public MenuBase(IntPtr wxObject)
      : base(wxObject) { }
      
    public MenuBase()
      : this(0) {}
      
    public MenuBase(uint style)
      : this(wxMenuBase_ctor2(style)) {}      
    
    public MenuBase(string titel)
      : this(titel, 0) {}
    
    public MenuBase(string titel, uint style)
      : this(wxString.SafeNew(titel), style) { }


        public MenuBase(wxString titel, uint style)
            : this(wxMenuBase_ctor1(Object.SafePtr(titel), style)) { }

        //---------------------------------------------------------------------
    
    public MenuItem Append(int id, string item)
    {
      return this.Append(id, item, "");
    }
    
    public MenuItem Append(int id, string item, string help)
    {
      return Append(id, item, help, ItemKind.wxITEM_NORMAL);
    }

        public MenuItem Append(int id, string item, string help, ItemKind kind)
        {
            return this.Append(id, wxString.SafeNew(item), wxString.SafeNew(help), kind);
        }
    public MenuItem Append(int id, wxString item, wxString help, ItemKind kind)
    {
      return (MenuItem)FindObject(wxMenuBase_Append(wxObject, id, Object.SafePtr(item), Object.SafePtr(help), kind), typeof(MenuItem));
    }
    
    public MenuItem Append(int id, string item, Menu subMenu)
    {
      return Append(id, item, subMenu, "");
    }

        public MenuItem Append(int id, string item, Menu subMenu, string help)
        {
            return this.Append(id, wxString.SafeNew(item), subMenu, wxString.SafeNew(help));
        }
    public MenuItem Append(int id, wxString item, Menu subMenu, wxString help)
    {
      return (MenuItem)FindObject(wxMenuBase_AppendSubMenu(wxObject, id, Object.SafePtr(item), Object.SafePtr(subMenu), Object.SafePtr(help)), typeof(MenuItem));
    }

    public MenuItem Append(MenuItem item) 
    {
      return (MenuItem)FindObject(wxMenuBase_AppendItem(wxObject, Object.SafePtr(item)), typeof(MenuItem));
    }

    //---------------------------------------------------------------------
    
    public MenuItem AppendCheckItem(int id, string item)
    {
      return AppendCheckItem(id, item, "");
    }

        public MenuItem AppendCheckItem(int id, string item, string help)
        {
            return this.AppendCheckItem(id, wxString.SafeNew(item), wxString.SafeNew( help));
        }
    public MenuItem AppendCheckItem(int id, wxString item, wxString help)
    {
      return (MenuItem)FindObject(wxMenuBase_AppendCheckItem(wxObject, id, Object.SafePtr(item), Object.SafePtr(help)), typeof(MenuItem));
    }

    //---------------------------------------------------------------------

    public MenuItem AppendSeparator()
    {
      return (MenuItem)FindObject(wxMenuBase_AppendSeparator(wxObject), typeof(MenuItem));
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem AppendRadioItem(int itemid, string text)
    {
      return AppendRadioItem(itemid, text, "");
    }

        public MenuItem AppendRadioItem(int itemid, string text, string help)
        {
            return this.AppendRadioItem(itemid, wxString.SafeNew(text), wxString.SafeNew(help));
        }
    public MenuItem AppendRadioItem(int itemid, wxString text, wxString help)
    {
      return (MenuItem)FindObject(wxMenuBase_AppendRadioItem(wxObject, itemid, Object.SafePtr(text), Object.SafePtr(help)), typeof(MenuItem));
    }

    //---------------------------------------------------------------------

    public void Check(int id, bool check)
    {
      wxMenuBase_Check(wxObject, id, check);
    }

    //---------------------------------------------------------------------

    public int GetMenuItemCount()
    {
      return wxMenuBase_GetMenuItemCount(wxObject);
    }

    public MenuItem GetMenuItem(int index)
    {
      return (MenuItem)FindObject(wxMenuBase_GetMenuItem(wxObject, index), typeof(MenuItem));
    }

    //---------------------------------------------------------------------
    
    public virtual void Break()
    {
      wxMenuBase_Break(wxObject);
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem Insert(int pos, MenuItem item)
    {
      return (MenuItem)FindObject(wxMenuBase_Insert(wxObject, pos, Object.SafePtr(item)), typeof(MenuItem));
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem Insert(int pos, int itemid, string text)
    {
      return Insert(pos, itemid, text, "", ItemKind.wxITEM_NORMAL);
    }
    
    public MenuItem Insert(int pos, int itemid, string text, string help)
    {
      return Insert(pos, itemid, text, help, ItemKind.wxITEM_NORMAL);
    }

        public MenuItem Insert(int pos, int itemid, string text, string help, ItemKind kind)
        {
            return this.Insert(pos, itemid, wxString.SafeNew(text), wxString.SafeNew(help), kind);
        }
    public MenuItem Insert(int pos, int itemid, wxString text, wxString help, ItemKind kind)
    {
      return (MenuItem)FindObject(wxMenuBase_Insert2(wxObject, pos, itemid, Object.SafePtr(text), Object.SafePtr(help), kind), typeof(MenuItem));
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem InsertSeparator(int pos)
    {
      return (MenuItem)FindObject(wxMenuBase_InsertSeparator(wxObject, pos), typeof(MenuItem));
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem InsertCheckItem(int pos, int itemid, string text)
    {
      return InsertCheckItem(pos, itemid, text, "");
    }

        public MenuItem InsertCheckItem(int pos, int itemid, string text, string help)
        {
            return this.InsertCheckItem(pos, itemid, wxString.SafeNew(text), wxString.SafeNew(help));
        }
    public MenuItem InsertCheckItem(int pos, int itemid, wxString text, wxString help)
    {
      return (MenuItem)FindObject(wxMenuBase_InsertCheckItem(wxObject, pos, itemid, Object.SafePtr(text), Object.SafePtr(help)), typeof(MenuItem));
    }    
    
    //---------------------------------------------------------------------
    
    public MenuItem InsertRadioItem(int pos, int itemid, string text)
    {
      return InsertCheckItem(pos, itemid, text, "");
    }

        public MenuItem InsertRadioItem(int pos, int itemid, string text, string help)
        {
            return this.InsertRadioItem(pos, itemid, wxString.SafeNew(text), wxString.SafeNew(help));
        }

    public MenuItem InsertRadioItem(int pos, int itemid, wxString text, wxString help)
    {
      return (MenuItem)FindObject(wxMenuBase_InsertRadioItem(wxObject, pos, itemid, Object.SafePtr(text), Object.SafePtr(help)), typeof(MenuItem));
    }        
    
    //---------------------------------------------------------------------

    public MenuItem Insert(int pos, int itemid, string text, Menu submenu)
    {
      return Insert(pos, itemid, text, submenu, "");
    }

        public MenuItem Insert(int pos, int itemid, string text, Menu submenu, string help)
        {
            return this.Insert(pos, itemid, wxString.SafeNew(text), submenu, wxString.SafeNew(help));
        }
    public MenuItem Insert(int pos, int itemid, wxString text, Menu submenu, wxString help)
    {
      return (MenuItem)FindObject(wxMenuBase_InsertSubMenu(wxObject, pos, itemid, Object.SafePtr(text), Object.SafePtr(submenu), Object.SafePtr(help)), typeof(MenuItem));
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem Prepend(MenuItem item)
    {
      return (MenuItem)FindObject(wxMenuBase_Prepend(wxObject, Object.SafePtr(item)), typeof(MenuItem));
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem Prepend(int itemid, string text)
    {
      return Prepend(itemid, text, "", ItemKind.wxITEM_NORMAL);
    }
    
    public MenuItem Prepend(int itemid, string text, string help)
    {
      return Prepend(itemid, text, help, ItemKind.wxITEM_NORMAL);
    }

        public MenuItem Prepend(int itemid, string text, string help, ItemKind kind)
        {
            return this.Prepend(itemid, wxString.SafeNew(text), wxString.SafeNew(help), kind);
        }
    public MenuItem Prepend(int itemid, wxString text, wxString help, ItemKind kind)
    {
      return (MenuItem)FindObject(wxMenuBase_Prepend2(wxObject, itemid, Object.SafePtr(text), Object.SafePtr(help), kind), typeof(MenuItem));
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem PrependSeparator()
    {
      return (MenuItem)FindObject(wxMenuBase_PrependSeparator(wxObject));
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem PrependCheckItem(int itemid, string text)
    {
      return PrependCheckItem(itemid, text, "");
    }

        public MenuItem PrependCheckItem(int itemid, string text, string help)
        {
            return this.PrependCheckItem(itemid, wxString.SafeNew(text), wxString.SafeNew(help));
        }
    public MenuItem PrependCheckItem(int itemid, wxString text, wxString help)
    {
      return (MenuItem)FindObject(wxMenuBase_PrependCheckItem(wxObject, itemid, Object.SafePtr(text), Object.SafePtr(help)), typeof(MenuItem));
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem PrependRadioItem(int itemid, string text)
    {
      return PrependRadioItem(itemid, text, "");
    }

        public MenuItem PrependRadioItem(int itemid, string text, string help)
        {
            return this.PrependRadioItem(itemid, wxString.SafeNew(text), wxString.SafeNew(help));
        }
    public MenuItem PrependRadioItem(int itemid, wxString text, wxString help)
    {
      return (MenuItem)FindObject(wxMenuBase_PrependRadioItem(wxObject, itemid, Object.SafePtr(text), Object.SafePtr(help)), typeof(MenuItem));
    }    
    
    //---------------------------------------------------------------------
    
    public MenuItem Prepend(int itemid, string text, Menu submenu)
    {
      return Prepend(itemid, text, submenu, "");
    }

        public MenuItem Prepend(int itemid, string text, Menu submenu, string help)
        {
            return this.Prepend(itemid, wxString.SafeNew(text), submenu, wxString.SafeNew(help));
        }
    public MenuItem Prepend(int itemid, wxString text, Menu submenu, wxString help)
    {
      return (MenuItem)FindObject(wxMenuBase_PrependSubMenu(wxObject, itemid, Object.SafePtr(text), Object.SafePtr(submenu), Object.SafePtr(help)), typeof(MenuItem));
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem Remove(int itemid)
    {
      return (MenuItem)FindObject(wxMenuBase_Remove(wxObject, itemid), typeof(MenuItem));
    }
    
    public MenuItem Remove(MenuItem item)
    {
      return (MenuItem)FindObject(wxMenuBase_Remove2(wxObject, Object.SafePtr(item)), typeof(MenuItem));
    }    
    
    //---------------------------------------------------------------------
    
    public bool Delete(int itemid)
    {
      return wxMenuBase_Delete(wxObject, itemid);
    }
    
    public bool Delete(MenuItem item)
    {
      return wxMenuBase_Delete2(wxObject, Object.SafePtr(item));
    }
    
    //---------------------------------------------------------------------
    
    public bool Destroy(int itemid)
    {
      return wxMenuBase_Destroy(wxObject, itemid);
    }
    
    public bool Destroy(MenuItem item)
    {
      return wxMenuBase_Destroy2(wxObject, Object.SafePtr(item));
    }
    
    //---------------------------------------------------------------------

        public virtual int FindItem(string item)
        {
            return this.FindItem(wxString.SafeNew(item));
        }
    public virtual int FindItem(wxString item)
    {
      return wxMenuBase_FindItem(wxObject, Object.SafePtr(item));
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem FindItem(int itemid)
    {
      Menu menuRef = null;
      return FindItem(itemid, ref menuRef);
    }
    
    public MenuItem FindItem(int itemid, ref Menu menu)
    {
      IntPtr menuRef = IntPtr.Zero;
      if (menu != null) 
      {
        menuRef = Object.SafePtr(menu);
      }
      return (MenuItem)FindObject(wxMenuBase_FindItem2(wxObject, itemid, ref menuRef), typeof(MenuItem));
    }
    
    //---------------------------------------------------------------------
     
    public MenuItem FindItemByPosition(int position)
    {
      return (MenuItem)FindObject(wxMenuBase_FindItemByPosition(wxObject, position), typeof(MenuItem));
    }
    
    //---------------------------------------------------------------------
    
    public void Enable(int itemid, bool enable)
    {
      wxMenuBase_Enable(wxObject, itemid, enable);
    }
    
    public bool IsEnabled(int itemid)
    {
      return wxMenuBase_IsEnabled(wxObject, itemid);
    }
    
    //---------------------------------------------------------------------
    
    public bool IsChecked(int itemid)
    {
      return wxMenuBase_IsChecked(wxObject, itemid);
    }
    
    //---------------------------------------------------------------------

        public void SetLabel(int itemid, string label)
        {
            this.SetLabel(itemid, wxString.SafeNew(label));
        }
    public void SetLabel(int itemid, wxString label)
    {
      wxMenuBase_SetLabel(wxObject, itemid, Object.SafePtr(label));
    }
    
    public string GetLabel(int itemid)
    {
      return new wxString(wxMenuBase_GetLabel(wxObject, itemid), true);
    }
    
    //---------------------------------------------------------------------

        public void SetHelpString(int itemid, string helpString)
        {
            this.SetHelpString(itemid, wxString.SafeNew(helpString));
        }
    public void SetHelpString(int itemid, wxString helpString)
    {
      wxMenuBase_SetHelpString(wxObject, itemid, Object.SafePtr(helpString));
    }
    
    public string GetHelpString(int itemid)
    {
      return new wxString(wxMenuBase_GetHelpString(wxObject, itemid), true);
    }
    
    //---------------------------------------------------------------------
    
    public string Title
    {
      get { return new wxString(wxMenuBase_GetTitle(wxObject), true); }
      set
            {
                wxString wxValue = wxString.SafeNew(value);
                wxMenuBase_SetTitle(wxObject, Object.SafePtr(wxValue));
            }
    }
    
    //---------------------------------------------------------------------
    
    public EvtHandler EventHandler
    {
      get { return (EvtHandler)FindObject(wxMenuBase_GetEventHandler(wxObject), typeof(EvtHandler)); }
      set { wxMenuBase_SetEventHandler(wxObject, Object.SafePtr(value)); }
    }
    
    //---------------------------------------------------------------------
    
    public Window InvokingWindow
    {
      get { return (Window)FindObject(wxMenuBase_GetInvokingWindow(wxObject), typeof(Window)); }
      set { wxMenuBase_SetInvokingWindow(wxObject, Object.SafePtr(value)); }
    }
    
    //---------------------------------------------------------------------
    
    public uint style
    {
      get { return wxMenuBase_GetStyle(wxObject); }
    }
    
    //---------------------------------------------------------------------
    
    public void UpdateUI()
    {
      UpdateUI(null);
    }
    
    public void UpdateUI(EvtHandler source)
    {
      wxMenuBase_UpdateUI(wxObject, Object.SafePtr(source));
    }
    
    //---------------------------------------------------------------------
    
    public MenuBar MenuBar
    {
      get { return (MenuBar)FindObject(wxMenuBase_GetMenuBar(wxObject), typeof(MenuBar)); }
    }
    
    //---------------------------------------------------------------------
    
    public bool Attached
    {
      get { return wxMenuBase_IsAttached(wxObject); }
    }
    
    //---------------------------------------------------------------------
    
    public Menu Parent
    {
      get { return (Menu)FindObject(wxMenuBase_GetParent(wxObject), typeof(Menu)); }
      set { wxMenuBase_SetParent(wxObject, Object.SafePtr(value)); }
    }
    
    //---------------------------------------------------------------------
    
    public MenuItem FindChildItem(int itemid)
    {
      return (MenuItem)FindObject(wxMenuBase_FindChildItem2(wxObject, itemid), typeof(MenuItem));
    }
    
    public MenuItem FindChildItem(int itemid, out int pos)
    {
      return (MenuItem)FindObject(wxMenuBase_FindChildItem(wxObject, itemid, out pos), typeof(MenuItem));
    }
    
    //---------------------------------------------------------------------
    
    public bool SendEvent(int itemid)
    {
      return SendEvent(itemid, -1);
    }
    
    public bool SendEvent(int itemid, int xchecked)
    {
      return wxMenuBase_SendEvent(wxObject, itemid, xchecked);
    }    
  }
  
  //---------------------------------------------------------------------
  // helper struct, stores added EventListeners...
  
  public struct MenuListener
  {
    public EventListener listener;
    public Object owner;
    public int id;
    
    public MenuListener( int id, EventListener listener, Object owner )
    {
      this.listener = listener;
      this.owner = owner;
      this.id = id;
    }
  }  
  
  //---------------------------------------------------------------------

  public class Menu : MenuBase
  {
    [DllImport("wx-c")] static extern IntPtr wxMenu_ctor(IntPtr titel, uint style);
    [DllImport("wx-c")] static extern IntPtr wxMenu_ctor2(uint style);
    
    //---------------------------------------------------------------------
    
    public ArrayList eventListeners = new ArrayList();

    // InvokingWindow does not work on Windows, so we 
    // need this...
    private Window parent = null;

    // if events were connected with Frame.MenuBar or Window.PopupMenu
    // that means with ConnectEvents(), we have a Invoking Window and can add 
    // the event directly to the EventHandler
    private bool eventsconnected = false; 
    
    //---------------------------------------------------------------------
     
    public Menu()
      : this(0) {}
      
    public Menu(uint style)
      : this(wxMenu_ctor2(style)) {}
    
    public Menu(string titel)
      : this(titel, 0) {}
    
    public Menu(string title, uint style)
      : this(wxString.SafeNew(title), style) { }

        public Menu(wxString title, uint style)
            : this(wxMenu_ctor(Object.SafePtr(title), style)) { }

        public Menu(IntPtr wxObject)
      : base(wxObject) { }
      
    //---------------------------------------------------------------------
      
    public void AddEvent(int inId, EventListener el, Object owner)
    {
      // This is the only way of handling menu selection events (maybe there is an other solution)
      // But for now we have to add the EventListener to the EventHandler of the invoking window,
      // otherwise nothing happens.
      // As int as we do not have an invoking window, which means, that for example the
      // MenuBar of this Menu isn't connected to a Frame, the EventListener gets only
      // added to the ArrayList, otherwise it gets directly added to the EventHandler of
      // the invoking window. When Frame.MenuBar is set, it will call ConnectEvents() 
      // for each Menu in MenuBar
      eventListeners.Add( new MenuListener( inId, el, owner ) );
      
      if ( eventsconnected )
        parent.AddCommandListener(Event.wxEVT_COMMAND_MENU_SELECTED, inId, el, owner);
    }  
    
    //---------------------------------------------------------------------
    // ConnectEvents gets only called from Window and Frame
    
    public void ConnectEvents(Window parent)
    {
      this.parent = parent;

      if ( eventListeners.Count > 0 )
      {
        foreach( MenuListener ml in eventListeners )
        {
          parent.AddCommandListener(Event.wxEVT_COMMAND_MENU_SELECTED, ml.id, ml.listener, ml.owner);
        }
      }
      
      eventsconnected = true;
    }
    
    //---------------------------------------------------------------------
    
    // This is for faster coding ;) and closes request on SourceForge ;))))
    // WL stands for with listener
    public MenuItem AppendWL(int id, string item, EventListener listener)
    {
      MenuItem tmpitem = Append(id, item, "");
      
      AddEvent( id, listener, tmpitem );
      
      return tmpitem;
    }
    
    public MenuItem AppendWL(int id, string item, string help, EventListener listener)
    {
      MenuItem tmpitem = Append(id, item, help, ItemKind.wxITEM_NORMAL);
      
      AddEvent( id, listener, tmpitem );
      
      return tmpitem;
    }
    
    public MenuItem AppendWL(int id, string item, string help, ItemKind kind, EventListener listener)
    {
      MenuItem tmpitem = Append(id, item, help, kind);
      
      AddEvent( id, listener, tmpitem );
      
      return tmpitem;
    }
    
    public MenuItem AppendWL(int id, string item, Menu subMenu, EventListener listener)
    {
      MenuItem tmpitem = Append(id, item, subMenu, "");
      
      AddEvent( id, listener, tmpitem );
      
      return tmpitem;
    }

    public MenuItem AppendWL(int id, string item, Menu subMenu, string help, EventListener listener)
    {
      MenuItem tmpitem = Append(id, item, subMenu, help);
      
      AddEvent( id, listener, tmpitem );
      
      return tmpitem;
    }

    public MenuItem Append(MenuItem item, EventListener listener) 
    {
      MenuItem tmpitem = Append(item);
      AddEvent(item.ID, listener, tmpitem);
      return tmpitem;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.