]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/menu.cpp
Removed wxClearVariant() and wxReleaseVariant().
[wxWidgets.git] / src / os2 / menu.cpp
index d5d5e3ca704daeee494abb433728c82bc3659e45..065a8a7dc004cc6b8245e98b40fd829dd23f80b2 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        menu.cpp
+// Name:        src/os2/menu.cpp
 // Purpose:     wxMenu, wxMenuBar, wxMenuItem
 // Author:      David Webster
 // Modified by:
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
+#include "wx/menu.h"
+
 #ifndef WX_PRECOMP
+    #include "wx/app.h"
     #include "wx/frame.h"
-    #include "wx/menu.h"
     #include "wx/utils.h"
     #include "wx/intl.h"
+    #include "wx/log.h"
 #endif
 
 #if wxUSE_OWNER_DRAWN
@@ -24,9 +27,6 @@
 #endif
 
 #include "wx/os2/private.h"
-#include "wx/menu.h"
-#include "wx/menuitem.h"
-#include "wx/log.h"
 
 // other standard headers
 #include <string.h>
 // global variables
 // ----------------------------------------------------------------------------
 
-extern wxMenu *wxCurrentPopupMenu;
+extern wxMenu*                      wxCurrentPopupMenu;
 
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
 
-// the (popup) menu title has this special id
-static const int idMenuTitle = -2;
+//
+// The (popup) menu title has this special id
+//
+static const int                    idMenuTitle = -3;
+
+//
+// The unique ID for Menus
+//
+USHORT                              wxMenu::m_nextMenuId = 0;
 
 // ----------------------------------------------------------------------------
 // macros
 // ----------------------------------------------------------------------------
 
-#if !USE_SHARED_LIBRARY
     IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
     IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
-#endif
 
 // ============================================================================
 // implementation
@@ -61,561 +66,609 @@ static const int idMenuTitle = -2;
 // wxMenu construction, adding and removing menu items
 // ---------------------------------------------------------------------------
 
+//
 // Construct a menu with optional title (then use append)
-void wxMenu::Init(const wxString& title, const wxFunction func )
+//
+void wxMenu::Init()
 {
-    m_title = title;
-    m_parent = NULL;
-    m_eventHandler = this;
-    m_pInvokingWindow = NULL;
-    m_doBreak = FALSE ;
-    m_noItems = 0;
-    m_menuBar = NULL;
-    m_hMenu = 0; //(WXHMENU) CreatePopupMenu();
-    m_savehMenu = 0 ;
-    m_topLevelMenu = this;
-    m_clientData = (void*) NULL;
-
-    if ( !!m_title )
+    m_bDoBreak = false;
+    m_nStartRadioGroup = -1;
+
+    //
+    // Create the menu (to be used as a submenu or a popup)
+    //
+    if ((m_hMenu =  ::WinCreateWindow( HWND_DESKTOP
+                                      ,WC_MENU
+                                      ,"Menu"
+                                      ,0L
+                                      ,0L
+                                      ,0L
+                                      ,0L
+                                      ,0L
+                                      ,NULLHANDLE
+                                      ,HWND_TOP
+                                      ,0L
+                                      ,NULL
+                                      ,NULL
+                                     )) == 0)
     {
-        Append(idMenuTitle, m_title) ;
-        AppendSeparator() ;
+        wxLogLastError(wxT("WinLoadMenu"));
     }
+    m_vMenuData.iPosition   = 0;
+    m_vMenuData.afStyle     = MIS_SUBMENU | MIS_TEXT;
+    m_vMenuData.afAttribute = (USHORT)0;
+    m_vMenuData.id          = m_nextMenuId++;
+    m_vMenuData.hwndSubMenu = m_hMenu;
+    m_vMenuData.hItem       = NULLHANDLE;
+
+    //
+    // If we have a title, insert it in the beginning of the menu
+    //
+    if (!m_title.empty())
+    {
+        Append( idMenuTitle
+               ,m_title
+               ,wxEmptyString
+               ,wxITEM_NORMAL
+              );
+        AppendSeparator();
+    }
+} // end of wxMenu::Init
 
-    Callback(func);
-}
-
+//
 // The wxWindow destructor will take care of deleting the submenus.
+//
 wxMenu::~wxMenu()
 {
-    // free Windows resources
-    if ( m_hMenu )
+    //
+    // We should free PM resources only if PM doesn't do it for us
+    // which happens if we're attached to a menubar or a submenu of another
+    // menu
+    if (!IsAttached() && !GetParent())
     {
-//        ::DestroyMenu((HMENU)m_hMenu);
-        m_hMenu = 0;
+        if (!::WinDestroyWindow((HWND)GetHmenu()) )
+        {
+            wxLogLastError(wxT("WinDestroyWindow"));
+        }
     }
 
-    // delete submenus
-    wxNode *node = m_menuItems.First();
-    while ( node )
-    {
-        wxMenuItem *item = (wxMenuItem *)node->Data();
-
-        // Delete child menus.
-        // Beware: they must not be appended to children list!!!
-        // (because order of delete is significant)
-        if ( item->IsSubMenu() )
-            item->DeleteSubMenu();
-
-        wxNode *next = node->Next();
-        delete item;
-        delete node;
-        node = next;
-    }
-}
+#if wxUSE_ACCEL
+    //
+    // Delete accels
+    //
+    WX_CLEAR_ARRAY(m_vAccels);
+#endif // wxUSE_ACCEL
+} // end of wxMenu::~wxMenu
 
 void wxMenu::Break()
 {
-    m_doBreak = TRUE;
-}
+    // this will take effect during the next call to Append()
+    m_bDoBreak = true;
+} // end of wxMenu::Break
 
-// function appends a new item or submenu to the menu
-void wxMenu::Append(wxMenuItem *pItem)
+void wxMenu::Attach(
+  wxMenuBarBase*                    pMenubar
+)
 {
-    wxCHECK_RET( pItem != NULL, wxT("can't append NULL item to the menu") );
+    wxMenuBase::Attach(pMenubar);
+    EndRadioGroup();
+} // end of wxMenu::Break;
 
 #if wxUSE_ACCEL
-    // check for accelerators: they are given after '\t'
-    wxString label = pItem->GetName();
-    int posTab = label.Find(wxT('\t'));
-    if ( posTab != wxNOT_FOUND ) {
-        // parse the accelerator string
-        int keyCode = 0;
-        int accelFlags = wxACCEL_NORMAL;
-        wxString current;
-        for ( size_t n = (size_t)posTab + 1; n < label.Len(); n++ ) {
-            if ( (label[n] == '+') || (label[n] == '-') ) {
-                if ( current == _("ctrl") )
-                    accelFlags |= wxACCEL_CTRL;
-                else if ( current == _("alt") )
-                    accelFlags |= wxACCEL_ALT;
-                else if ( current == _("shift") )
-                    accelFlags |= wxACCEL_SHIFT;
-                else {
-                    wxLogDebug(wxT("Unknown accel modifier: '%s'"),
-                               current.c_str());
-                }
-
-                current.Empty();
-            }
-            else {
-                current += wxTolower(label[n]);
-            }
+
+int wxMenu::FindAccel(
+  int                               nId
+) const
+{
+    size_t                          n;
+    size_t                          nCount = m_vAccels.GetCount();
+
+    for (n = 0; n < nCount; n++)
+        if (m_vAccels[n]->m_command == nId)
+            return n;
+    return wxNOT_FOUND;
+} // end of wxMenu::FindAccel
+
+void wxMenu::UpdateAccel(
+  wxMenuItem*                       pItem
+)
+{
+    if (pItem->IsSubMenu())
+    {
+        wxMenu*                     pSubmenu = pItem->GetSubMenu();
+        wxMenuItemList::compatibility_iterator node = pSubmenu->GetMenuItems().GetFirst();
+
+        while (node)
+        {
+            UpdateAccel(node->GetData());
+            node = node->GetNext();
         }
+    }
+    else if (!pItem->IsSeparator())
+    {
+        //
+        // Recurse upwards: we should only modify m_accels of the top level
+        // menus, not of the submenus as wxMenuBar doesn't look at them
+        // (alternative and arguable cleaner solution would be to recurse
+        // downwards in GetAccelCount() and CopyAccels())
+        //
+        if (GetParent())
+        {
+            GetParent()->UpdateAccel(pItem);
+            return;
+        }
+
+        //
+        // Find the (new) accel for this item
+        //
+        wxAcceleratorEntry*         pAccel = wxAcceleratorEntry::Create(pItem->GetItemLabel());
+
+        if (pAccel)
+            pAccel->m_command = pItem->GetId();
 
-        if ( current.IsEmpty() ) {
-            wxLogDebug(wxT("No accel key found, accel string ignored."));
+        //
+        // Find the old one
+        //
+        size_t                      n = FindAccel(pItem->GetId());
+
+        if (n == (size_t)wxNOT_FOUND)
+        {
+            //
+            // No old, add new if any
+            //
+            if (pAccel)
+                m_vAccels.Add(pAccel);
+            else
+                return;
         }
-        else {
-            if ( current.Len() == 1 ) {
-                // it's a letter
-                keyCode = wxToupper(current[0U]);
-            }
-            else {
-                // it should be a function key
-                if ( current[0U] == 'f' && isdigit(current[1U]) &&
-                     (current.Len() == 2 ||
-                     (current.Len() == 3 && isdigit(current[2U]))) ) {
-                    int n;
-                    wxSscanf(current.c_str() + 1, wxT("%d"), &n);
-
-                    keyCode = VK_F1 + n - 1;
-                }
-                else {
-                    wxLogDebug(wxT("Unrecognized accel key '%s', accel "
-                                  "string ignored."), current.c_str());
-                }
-            }
+        else
+        {
+            //
+            // Replace old with new or just remove the old one if no new
+            //
+            delete m_vAccels[n];
+            if (pAccel)
+                m_vAccels[n] = pAccel;
+            else
+                m_vAccels.RemoveAt(n);
         }
 
-        if ( keyCode ) {
-            // do add an entry
-            m_accelKeyCodes.Add(keyCode);
-            m_accelFlags.Add(accelFlags);
-            m_accelIds.Add(pItem->GetId());
+        if (IsAttached())
+        {
+            GetMenuBar()->RebuildAccelTable();
         }
     }
+} // wxMenu::UpdateAccel
+
 #endif // wxUSE_ACCEL
 
-    UINT flags = 0;
+//
+// Append a new item or submenu to the menu
+//
+bool wxMenu::DoInsertOrAppend( wxMenuItem* pItem,
+                               size_t      nPos )
+{
+    wxMenu*    pSubmenu = pItem->GetSubMenu();
+    MENUITEM&  rItem = (pSubmenu != NULL)?pSubmenu->m_vMenuData:
+                       pItem->m_vMenuData;
 
-    // TODO:
-/*
-    // if "Break" has just been called, insert a menu break before this item
-    // (and don't forget to reset the flag)
-    if ( m_doBreak ) {
-        flags |= MF_MENUBREAK;
-        m_doBreak = FALSE;
-    }
+    ERRORID    vError;
+    wxString   sError;
 
-    if ( pItem->IsSeparator() ) {
-        flags |= MF_SEPARATOR;
-    }
+#if wxUSE_ACCEL
+    UpdateAccel(pItem);
+#endif // wxUSE_ACCEL
 
-    // id is the numeric id for normal menu items and HMENU for submenus as
-    // required by ::AppendMenu() API
-    UINT id;
-    wxMenu *submenu = pItem->GetSubMenu();
-    if ( submenu != NULL ) {
-        wxASSERT( submenu->GetHMenu() != (WXHMENU) NULL );
+    //
+    // If "Break" has just been called, insert a menu break before this item
+    // (and don't forget to reset the flag)
+    //
+    if (m_bDoBreak)
+    {
+        rItem.afStyle |= MIS_BREAK;
+        m_bDoBreak = false;
+    }
 
-        id = (UINT)submenu->GetHMenu();
-        submenu->m_topLevelMenu = m_topLevelMenu;
-        submenu->m_parent       = this;
-        submenu->m_savehMenu    = (WXHMENU)id;
-        submenu->m_hMenu        = 0;
+    //
+    // Id is the numeric id for normal menu items and HMENU for submenus as
+    // required by ::MM_INSERTITEM message API
+    //
+    if (pSubmenu != NULL)
+    {
+        wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu"));
+        pSubmenu->SetParent(this);
 
-        flags |= MF_POPUP;
+        rItem.iPosition = 0; // submenus have a 0 position
+        rItem.id        = (USHORT)pSubmenu->GetHMenu();
+        rItem.afStyle  |= MIS_SUBMENU | MIS_TEXT;
     }
-    else {
-        id = pItem->GetId();
+    else
+    {
+        rItem.id = (USHORT)pItem->GetId();
     }
 
-    const char* pData;
+    char *pData = NULL;
 
 #if wxUSE_OWNER_DRAWN
-    if ( pItem->IsOwnerDrawn() ) {  // want to get {Measure|Draw}Item messages?
-        // item draws itself, pass pointer to it in data parameter
-        flags |= MF_OWNERDRAW;
-        pData = (const char*)pItem;
+    if (pItem->IsOwnerDrawn())
+    {
+        //
+        // Want to get {Measure|Draw}Item messages?
+        // item draws itself, passing pointer to data doesn't work in OS/2
+        // Will eventually need to set the image handle somewhere into vItem.hItem
+        //
+        rItem.afStyle             |= MIS_OWNERDRAW;
+        pData                      = NULL;
+        rItem.hItem                = (HBITMAP)pItem->GetBitmap().GetHBITMAP();
+        pItem->m_vMenuData.afStyle = rItem.afStyle;
+        pItem->m_vMenuData.hItem   = rItem.hItem;
     }
     else
 #endif
+    if (pItem->IsSeparator())
     {
-        // menu is just a normal string (passed in data parameter)
-        flags |= MF_STRING;
-        pData = label;
-    }
-    if ( !::AppendMenu(GetHmenu(), flags, id, pData) )
-    {
-        wxLogLastError("AppendMenu");
+        rItem.afStyle = MIS_SEPARATOR;
     }
     else
     {
-        if ( id == idMenuTitle )
+        if (pItem->GetId() == idMenuTitle)
         {
-            // visually select the menu title
-            MENUITEMINFO mii;
-            mii.cbSize = sizeof(mii);
-            mii.fMask = MIIM_STATE;
-            mii.fState = MFS_DEFAULT;
-
-            if ( !SetMenuItemInfo(GetHmenu(), (unsigned)id, FALSE, &mii) )
-            {
-                wxLogLastError(wxT("SetMenuItemInfo"));
-            }
+            // Item is an unselectable title to be passed via pData
+            rItem.afStyle = MIS_STATIC;
         }
-        m_menuItems.Append(pItem);
-        m_noItems++;
+        else
+        {
+            //
+            // Menu is just a normal string (passed in data parameter)
+            //
+            rItem.afStyle |= MIS_TEXT;
+        }
+        pData = (char*) pItem->GetItemLabel().wx_str();
     }
-*/
-}
-
-void wxMenu::AppendSeparator()
-{
-    Append(new wxMenuItem(this, ID_SEPARATOR));
-}
-
-// Pullright item
-void wxMenu::Append(int id,
-                    const wxString& label,
-                    wxMenu *SubMenu,
-                    const wxString& helpString)
-{
-    Append(new wxMenuItem(this, id, label, helpString, FALSE, SubMenu));
-}
-
-// Ordinary menu item
-void wxMenu::Append(int id,
-                    const wxString& label,
-                    const wxString& helpString,
-                    bool checkable)
-{
-    // 'checkable' parameter is useless for Windows.
-    Append(new wxMenuItem(this, id, label, helpString, checkable));
-}
 
-// delete item by id
-void wxMenu::Delete(int id)
-{
-    wxMenuItem *item = NULL;
-    int pos;
-    wxNode *node;
-    for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++)
+    if (nPos == (size_t)-1)
     {
-        item = (wxMenuItem *)node->Data();
-        if ( item->GetId() == id )
-            break;
+        rItem.iPosition = MIT_END;
+    }
+    else
+    {
+        rItem.iPosition = (SHORT)nPos;
     }
 
-    wxCHECK_RET( node, wxT("wxMenu::Delete(): item doesn't exist") );
+    APIRET                          rc;
 
-    HMENU menu = GetHmenu();
+    rc = (APIRET)::WinSendMsg( GetHmenu()
+                              ,MM_INSERTITEM
+                              ,(MPARAM)&rItem
+                              ,(MPARAM)pData
+                             );
+#if wxUSE_OWNER_DRAWN
+    if (pItem->IsOwnerDrawn())
+    {
+        MENUITEM                   vMenuItem;
+
+        ::WinSendMsg( GetHmenu()
+                     ,MM_QUERYITEM
+                     ,MPFROM2SHORT( (USHORT)pItem->GetId()
+                                   ,(USHORT)(FALSE)
+                                  )
+                     ,&vMenuItem
+                    );
+    }
+#endif
 
-    wxMenu *pSubMenu = item->GetSubMenu();
-    if ( pSubMenu != NULL )
+    if (rc == (APIRET)MIT_MEMERROR || rc == (APIRET)MIT_ERROR)
     {
-//        RemoveMenu(menu, (UINT)pos, MF_BYPOSITION);
-        pSubMenu->m_hMenu = pSubMenu->m_savehMenu;
-        pSubMenu->m_savehMenu = 0;
-        pSubMenu->m_parent = NULL;
-        //     RemoveChild(item->subMenu);
-        pSubMenu->m_topLevelMenu = NULL;
-        // TODO: Why isn't subMenu deleted here???
-        // Will put this in for now. Assuming this is supposed
-        // to delete the menu, not just remove it.
-        item->DeleteSubMenu();
+        vError = ::WinGetLastError(vHabmain);
+        sError = wxPMErrorToStr(vError);
+        wxLogError(wxT("Error inserting or appending a menuitem. Error: %s\n"), sError.c_str());
+        wxLogLastError(wxT("Insert or AppendMenu"));
+        return false;
     }
-//    else
-//    {
-//        DeleteMenu(menu, (UINT)pos, MF_BYPOSITION);
-//    }
 
-    m_menuItems.DeleteNode(node);
-    delete item;
-}
+    //
+    // If we're already attached to the menubar, we must update it
+    //
+    if (IsAttached() && GetMenuBar()->IsAttached())
+    {
+        GetMenuBar()->Refresh();
+    }
 
-#if wxUSE_ACCEL
+    return true;
+} // end of wxMenu::DoInsertOrAppend
 
-// ---------------------------------------------------------------------------
-// accelerator helpers
-// ---------------------------------------------------------------------------
+void wxMenu::EndRadioGroup()
+{
+    //
+    // We're not inside a radio group any longer
+    //
+    m_nStartRadioGroup = -1;
+} // end of wxMenu::EndRadioGroup
 
-// create the wxAcceleratorEntries for our accels and put them into provided
-// array - return the number of accels we have
-size_t wxMenu::CopyAccels(wxAcceleratorEntry *accels) const
+wxMenuItem* wxMenu::DoAppend( wxMenuItem* pItem )
 {
-    size_t count = GetAccelCount();
-    for ( size_t n = 0; n < count; n++ )
-    {
-        (*accels++).Set(m_accelFlags[n], m_accelKeyCodes[n], m_accelIds[n]);
-    }
+    wxCHECK_MSG( pItem, NULL, wxT("NULL item in wxMenu::DoAppend") );
 
-    return count;
-}
+    bool bCheck = false;
 
-#endif // wxUSE_ACCEL
+    if (pItem->GetKind() == wxITEM_RADIO)
+    {
+        int                         nCount = GetMenuItemCount();
 
-// ---------------------------------------------------------------------------
-// wxMenu functions implemented in wxMenuItem
-// ---------------------------------------------------------------------------
+        if (m_nStartRadioGroup == -1)
+        {
+            //
+            // Start a new radio group
+            //
+            m_nStartRadioGroup = nCount;
+
+            //
+            // For now it has just one element
+            //
+            pItem->SetAsRadioGroupStart();
+            pItem->SetRadioGroupEnd(m_nStartRadioGroup);
+
+            //
+            // Ensure that we have a checked item in the radio group
+            //
+            bCheck = true;
+        }
+        else // extend the current radio group
+        {
+            //
+            // We need to update its end item
+            //
+            pItem->SetRadioGroupStart(m_nStartRadioGroup);
 
-void wxMenu::Enable(int id, bool Flag)
-{
-    wxMenuItem *item = FindItemForId(id);
-    wxCHECK_RET( item != NULL, wxT("can't enable non-existing menu item") );
+            wxMenuItemList::compatibility_iterator node = GetMenuItems().Item(m_nStartRadioGroup);
+
+            if (node)
+            {
+                node->GetData()->SetRadioGroupEnd(nCount);
+            }
+            else
+            {
+                wxFAIL_MSG( wxT("where is the radio group start item?") );
+            }
+        }
+    }
+    else // not a radio item
+    {
+        EndRadioGroup();
+    }
 
-    item->Enable(Flag);
-}
+    if (!wxMenuBase::DoAppend(pItem) || !DoInsertOrAppend(pItem))
+    {
+        return NULL;
+    }
+    if (bCheck)
+    {
+        //
+        // Check the item initially
+        //
+        pItem->Check(true);
+    }
+    return pItem;
+} // end of wxMenu::DoAppend
 
-bool wxMenu::IsEnabled(int id) const
+wxMenuItem* wxMenu::DoInsert(
+  size_t                            nPos
+, wxMenuItem*                       pItem
+)
 {
-    wxMenuItem *item = FindItemForId(id);
-    wxCHECK_MSG( item != NULL, FALSE, wxT("invalid item id") );
-
-    return item->IsEnabled();
-}
+    if ( wxMenuBase::DoInsert( nPos
+                               ,pItem) &&
+             DoInsertOrAppend( pItem
+                              ,nPos
+                 ))
+         return pItem;
+    else
+        return NULL;
+} // end of wxMenu::DoInsert
 
-void wxMenu::Check(int id, bool Flag)
+wxMenuItem* wxMenu::DoRemove(
+  wxMenuItem*                       pItem
+)
 {
-    wxMenuItem *item = FindItemForId(id);
-    wxCHECK_RET( item != NULL, wxT("can't get status of non-existing menu item") );
+    //
+    // We need to find the items position in the child list
+    //
+    size_t                          nPos;
+    wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
 
-    item->Check(Flag);
-}
+    for (nPos = 0; node; nPos++)
+    {
+        if (node->GetData() == pItem)
+            break;
+        node = node->GetNext();
+    }
 
-bool wxMenu::IsChecked(int id) const
-{
-    wxMenuItem *item = FindItemForId(id);
-    wxCHECK_MSG( item != NULL, FALSE, wxT("invalid item id") );
+    //
+    // DoRemove() (unlike Remove) can only be called for existing item!
+    //
+    wxCHECK_MSG(node, NULL, wxT("bug in wxMenu::Remove logic"));
 
-    return item->IsChecked();
-}
+#if wxUSE_ACCEL
+    //
+    // Remove the corresponding accel from the accel table
+    //
+    int                             n = FindAccel(pItem->GetId());
 
-void wxMenu::SetLabel(int id, const wxString& label)
-{
-    wxMenuItem *item = FindItemForId(id) ;
-    wxCHECK_RET( item, wxT("wxMenu::SetLabel: no such item") );
+    if (n != wxNOT_FOUND)
+    {
+        delete m_vAccels[n];
+        m_vAccels.RemoveAt(n);
+    }
 
-    item->SetName(label);
-}
+#endif // wxUSE_ACCEL
+    //
+    // Remove the item from the menu
+    //
+    ::WinSendMsg( GetHmenu()
+                 ,MM_REMOVEITEM
+                 ,MPFROM2SHORT(pItem->GetId(), TRUE)
+                 ,(MPARAM)0
+                );
+    if (IsAttached() && GetMenuBar()->IsAttached())
+    {
+        //
+        // Otherwise, the chane won't be visible
+        //
+        GetMenuBar()->Refresh();
+    }
 
-wxString wxMenu::GetLabel(int id) const
-{
-    wxString label;
-    wxMenuItem *pItem = FindItemForId(id) ;
-    if (pItem)
-        label = pItem->GetName() ;
-    else
-        wxFAIL_MSG(wxT("wxMenu::GetLabel: item doesn't exist"));
+    //
+    // And from internal data structures
+    //
+    return wxMenuBase::DoRemove(pItem);
+} // end of wxMenu::DoRemove
 
-    return label;
-}
+// ---------------------------------------------------------------------------
+// accelerator helpers
+// ---------------------------------------------------------------------------
 
-void wxMenu::SetHelpString(int itemId, const wxString& helpString)
-{
-    wxMenuItem *item = FindItemForId (itemId);
-    if (item)
-        item->SetHelp(helpString);
-    else
-        wxFAIL_MSG(wxT("wxMenu::SetHelpString: item doesn't exist"));
-}
+#if wxUSE_ACCEL
 
-wxString wxMenu::GetHelpString (int itemId) const
+//
+// Create the wxAcceleratorEntries for our accels and put them into provided
+// array - return the number of accels we have
+//
+size_t wxMenu::CopyAccels(
+  wxAcceleratorEntry*               pAccels
+) const
 {
-    wxString help;
-    wxMenuItem *item = FindItemForId (itemId);
-    if (item)
-        help = item->GetHelp();
-    else
-        wxFAIL_MSG(wxT("wxMenu::GetHelpString: item doesn't exist"));
+    size_t                          nCount = GetAccelCount();
+
+    for (size_t n = 0; n < nCount; n++)
+    {
+        *pAccels++ = *m_vAccels[n];
+    }
+    return nCount;
+} // end of wxMenu::CopyAccels
 
-    return help;
-}
+#endif // wxUSE_ACCEL
 
 // ---------------------------------------------------------------------------
-// wxMenu title
+// set wxMenu title
 // ---------------------------------------------------------------------------
 
-void wxMenu::SetTitle(const wxString& label)
+void wxMenu::SetTitle( const wxString& rLabel )
 {
-    bool hasNoTitle = m_title.IsEmpty();
-    m_title = label;
+    bool bHasNoTitle = m_title.empty();
+    HWND hMenu = GetHmenu();
 
-    HMENU hMenu = GetHmenu();
-// TODO
-/*
-    if ( hasNoTitle )
+    m_title = rLabel;
+    if (bHasNoTitle)
     {
-        if ( !label.IsEmpty() )
+        if (!rLabel.empty())
         {
-            if ( !InsertMenu(hMenu, 0u, MF_BYPOSITION | MF_STRING,
-                             (unsigned)idMenuTitle, m_title) ||
-                 !InsertMenu(hMenu, 1u, MF_BYPOSITION, (unsigned)-1, NULL) )
+            if (!::WinSetWindowText(hMenu, rLabel.c_str()))
             {
-                wxLogLastError(wxT("InsertMenu"));
+                wxLogLastError(wxT("SetMenuTitle"));
             }
         }
     }
     else
     {
-        if ( label.IsEmpty() )
+        if (rLabel.empty() )
         {
-            // remove the title and the separator after it
-            if ( !RemoveMenu(hMenu, 0, MF_BYPOSITION) ||
-                 !RemoveMenu(hMenu, 0, MF_BYPOSITION) )
-            {
-                wxLogLastError("RemoveMenu");
-            }
+            ::WinSendMsg( GetHmenu()
+                         ,MM_REMOVEITEM
+                         ,MPFROM2SHORT(hMenu, TRUE)
+                         ,(MPARAM)0
+                        );
         }
         else
         {
-            // modify the title
-            if ( !ModifyMenu(hMenu, 0u,
-                        MF_BYPOSITION | MF_STRING,
-                        (unsigned)idMenuTitle, m_title) )
+            //
+            // Modify the title
+            //
+            if (!::WinSetWindowText(hMenu, rLabel.c_str()))
             {
-                wxLogLastError("ModifyMenu");
+                wxLogLastError(wxT("SetMenuTitle"));
             }
         }
     }
-
-    // put the title string in bold face
-    if ( !m_title.IsEmpty() )
-    {
-        MENUITEMINFO mii;
-        mii.cbSize = sizeof(mii);
-        mii.fMask = MIIM_STATE;
-        mii.fState = MFS_DEFAULT;
-
-        if ( !SetMenuItemInfo(hMenu, (unsigned)idMenuTitle, FALSE, &mii) )
-        {
-            wxLogLastError("SetMenuItemInfo");
-        }
-    }
-*/
-}
-
-const wxString wxMenu::GetTitle() const
-{
-    return m_title;
-}
+} // end of wxMenu::SetTitle
 
 // ---------------------------------------------------------------------------
 // event processing
 // ---------------------------------------------------------------------------
 
-bool wxMenu::OS2Command(WXUINT WXUNUSED(param), WXWORD id)
+bool wxMenu::OS2Command( WXUINT WXUNUSED(uParam),
+                         WXWORD vId )
 {
-    // ignore commands from the menu title
-
-    if ( id != (WXWORD)idMenuTitle )
-    {
-        wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED);
-        event.SetEventObject( this );
-        event.SetId( id );
-        event.SetInt( id );
-        ProcessCommand(event);
-    }
-
-    return TRUE;
-}
-
-bool wxMenu::ProcessCommand(wxCommandEvent & event)
-{
-    bool processed = FALSE;
-
-    // Try a callback
-    if (m_callback)
-    {
-        (void)(*(m_callback))(*this, event);
-        processed = TRUE;
-    }
+    //
+    // Ignore commands from the menu title
+    //
 
-    // Try the menu's event handler
-    if ( !processed && GetEventHandler())
+    if (vId != (WXWORD)idMenuTitle)
     {
-        processed = GetEventHandler()->ProcessEvent(event);
+        SendEvent( vId
+                  ,(int)::WinSendMsg( GetHmenu()
+                                     ,MM_QUERYITEMATTR
+                                     ,MPFROMSHORT(vId)
+                                     ,(MPARAM)MIA_CHECKED
+                                    )
+                 );
     }
-
-    // Try the window the menu was popped up from (and up through the
-    // hierarchy)
-    wxWindow *win = GetInvokingWindow();
-    if ( !processed && win )
-        processed = win->GetEventHandler()->ProcessEvent(event);
-
-    return processed;
-}
+    return true;
+} // end of wxMenu::OS2Command
 
 // ---------------------------------------------------------------------------
-// Item search
+// other
 // ---------------------------------------------------------------------------
 
-// Finds the item id matching the given string, -1 if not found.
-int wxMenu::FindItem (const wxString& itemString) const
+wxWindow* wxMenu::GetWindow() const
 {
-    wxString itemLabel = wxStripMenuCodes(itemString);
-    for ( wxNode *node = m_menuItems.First(); node; node = node->Next() )
-    {
-        wxMenuItem *item = (wxMenuItem *)node->Data();
-        if ( item->IsSubMenu() )
-        {
-            int ans = item->GetSubMenu()->FindItem(itemString);
-            if ( ans != wxNOT_FOUND )
-                return ans;
-        }
-        else if ( !item->IsSeparator() )
-        {
-            wxString label = wxStripMenuCodes(item->GetName());
-            if ( itemLabel == label )
-                return item->GetId();
-        }
-    }
-
-    return wxNOT_FOUND;
-}
+    if (m_invokingWindow != NULL)
+        return m_invokingWindow;
+    else if ( GetMenuBar() != NULL)
+        return GetMenuBar()->GetFrame();
 
-wxMenuItem *wxMenu::FindItemForId(int itemId, wxMenu ** itemMenu) const
+    return NULL;
+} // end of wxMenu::GetWindow
+
+// recursive search for item by id
+wxMenuItem* wxMenu::FindItem(
+  int                               nItemId
+, ULONG                             hItem
+, wxMenu**                          ppItemMenu
+) const
 {
-    if ( itemMenu )
-        *itemMenu = NULL;
+    if ( ppItemMenu )
+        *ppItemMenu = NULL;
+
+    wxMenuItem*                     pItem = NULL;
 
-    wxMenuItem *item = NULL;
-    for ( wxNode *node = m_menuItems.First(); node && !item; node = node->Next() )
+    for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst();
+          node && !pItem;
+          node = node->GetNext() )
     {
-        item = (wxMenuItem *)node->Data();
+        pItem = node->GetData();
 
-        if ( item->GetId() == itemId )
+        if ( pItem->GetId() == nItemId && pItem->m_vMenuData.hItem == hItem)
         {
-            if (itemMenu)
-                *itemMenu = (wxMenu *)this;
+            if ( ppItemMenu )
+                *ppItemMenu = (wxMenu *)this;
         }
-        else if ( item->IsSubMenu() )
+        else if ( pItem->IsSubMenu() )
         {
-            item = item->GetSubMenu()->FindItemForId(itemId, itemMenu);
+            pItem = pItem->GetSubMenu()->FindItem( nItemId
+                                                  ,hItem
+                                                  ,ppItemMenu
+                                                 );
+            if (pItem)
+                break;
         }
         else
         {
             // don't exit the loop
-            item = NULL;
+            pItem = NULL;
         }
     }
-
-    return item;
-}
-
-// ---------------------------------------------------------------------------
-// other
-// ---------------------------------------------------------------------------
-
-void wxMenu::Attach(wxMenuBar *menubar)
-{
-    // menu can be in at most one menubar because otherwise they would both
-    // delete the menu pointer
-    wxASSERT_MSG( !m_menuBar, wxT("menu belongs to 2 menubars, expect a crash") );
-
-    m_menuBar = menubar;
-    m_savehMenu = m_hMenu;
-    m_hMenu = 0;
-}
-
-void wxMenu::Detach()
-{
-    wxASSERT_MSG( m_menuBar, wxT("can't detach menu if it's not attached") );
-
-    m_hMenu = m_savehMenu;
-    m_savehMenu = 0;
-}
+    return pItem;
+} // end of wxMenu::FindItem
 
 // ---------------------------------------------------------------------------
 // Menu Bar
@@ -624,49 +677,52 @@ void wxMenu::Detach()
 void wxMenuBar::Init()
 {
     m_eventHandler = this;
-    m_menuCount = 0;
-    m_menus = NULL;
-    m_titles = NULL;
     m_menuBarFrame = NULL;
     m_hMenu = 0;
-}
+} // end of wxMenuBar::Init
 
 wxMenuBar::wxMenuBar()
 {
     Init();
-}
+} // end of wxMenuBar::wxMenuBar
 
-wxMenuBar::wxMenuBar( long WXUNUSED(style) )
+wxMenuBar::wxMenuBar(
+ long                               WXUNUSED(lStyle)
+)
 {
     Init();
-}
-
-wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[])
+} // end of wxMenuBar::wxMenuBar
+
+wxMenuBar::wxMenuBar(
+  int                               nCount
+, wxMenu*                           vMenus[]
+, const wxString                    sTitles[]
+, long                              WXUNUSED(lStyle)
+)
 {
     Init();
 
-    m_menuCount = count;
-    m_menus = menus;
-    m_titles = new wxString[count];
-
-    int i;
-    for ( i = 0; i < count; i++ )
-        m_titles[i] = titles[i];
-
-    for ( i = 0; i < count; i++ )
-        m_menus[i]->Attach(this);
-}
+    m_titles.Alloc(nCount);
+    for ( int i = 0; i < nCount; i++ )
+    {
+        m_menus.Append(vMenus[i]);
+        m_titles.Add(sTitles[i]);
+        vMenus[i]->Attach(this);
+    }
+} // end of wxMenuBar::wxMenuBar
 
 wxMenuBar::~wxMenuBar()
 {
-    for ( int i = 0; i < m_menuCount; i++ )
+    //
+    // We should free PM's resources only if PM doesn't do it for us
+    // which happens if we're attached to a frame
+    //
+    if (m_hMenu && !IsAttached())
     {
-        delete m_menus[i];
+        ::WinDestroyWindow((HMENU)m_hMenu);
+        m_hMenu = (WXHMENU)NULL;
     }
-
-    delete[] m_menus;
-    delete[] m_titles;
-}
+} // end of wxMenuBar::~wxMenuBar
 
 // ---------------------------------------------------------------------------
 // wxMenuBar helpers
@@ -674,515 +730,449 @@ wxMenuBar::~wxMenuBar()
 
 void wxMenuBar::Refresh()
 {
-    wxCHECK_RET( m_menuBarFrame, wxT("can't refresh a menubar withotu a frame") );
+    wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
 
-// TODO    DrawMenuBar((HWND)m_menuBarFrame->GetHWND()) ;
-}
+    WinSendMsg(GetWinHwnd(m_menuBarFrame), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
+} // end of wxMenuBar::Refresh
 
 WXHMENU wxMenuBar::Create()
 {
-    if (m_hMenu != 0 )
-    return m_hMenu;
+    HWND hFrame;
 
-    wxCHECK_MSG( !m_hMenu, TRUE, wxT("menubar already created") );
+    if (m_hMenu != 0 )
+        return m_hMenu;
 
-    m_hMenu = 0; // TODO: (WXHMENU)::CreateMenu();
+    wxCHECK_MSG(!m_hMenu, TRUE, wxT("menubar already created"));
 
-    if ( !m_hMenu )
+    //
+    // Menubars should be associated with a frame otherwise they are popups
+    //
+    if (m_menuBarFrame != NULL)
+        hFrame = GetWinHwnd(m_menuBarFrame);
+    else
+        hFrame = HWND_DESKTOP;
+    //
+    // Create an empty menu and then fill it with insertions
+    //
+    if ((m_hMenu =  ::WinCreateWindow( hFrame
+                                      ,WC_MENU
+                                      ,NULL
+                                      ,MS_ACTIONBAR | WS_SYNCPAINT | WS_VISIBLE
+                                      ,0L
+                                      ,0L
+                                      ,0L
+                                      ,0L
+                                      ,hFrame
+                                      ,HWND_TOP
+                                      ,FID_MENU
+                                      ,NULL
+                                      ,NULL
+                                     )) == 0)
     {
-        wxLogLastError("CreateMenu");
+        wxLogLastError(wxT("WinLoadMenu"));
     }
     else
     {
-        for ( int i = 0; i < m_menuCount; i++ )
+        size_t nCount = GetMenuCount(), i;
+        wxMenuList::iterator it;
+        for (i = 0, it = m_menus.begin(); i < nCount; i++, it++)
         {
-//            if ( !::AppendMenu((HMENU)m_hMenu, MF_POPUP | MF_STRING,
-//                               (UINT)m_menus[i]->GetHMenu(),
-//                               m_titles[i]) )
-//            {
-//                wxLogLastError("AppendMenu");
-//            }
-        }
-    }
-
-    return m_hMenu;
-}
-
-// ---------------------------------------------------------------------------
-// wxMenuBar functions forwarded to wxMenuItem
-// ---------------------------------------------------------------------------
-
-// Must only be used AFTER menu has been attached to frame,
-// otherwise use individual menus to enable/disable items
-void wxMenuBar::Enable(int id, bool enable)
-{
-    wxMenu *itemMenu = NULL;
-    wxMenuItem *item = FindItemForId(id, &itemMenu) ;
-
-    wxCHECK_RET( item, wxT("attempt to enable an item which doesn't exist") );
-
-    item->Enable(enable);
-}
-
-void wxMenuBar::EnableTop(int pos, bool enable)
-{
-    int flag = 0; // TODO enable ? MF_ENABLED : MF_GRAYED;;
-
-//    EnableMenuItem((HMENU)m_hMenu, pos, MF_BYPOSITION | flag);
-}
-
-// Must only be used AFTER menu has been attached to frame,
-// otherwise use individual menus
-void wxMenuBar::Check(int id, bool check)
-{
-    wxMenu *itemMenu = NULL;
-    wxMenuItem *item = FindItemForId(id, &itemMenu) ;
-
-    wxCHECK_RET( item, wxT("attempt to check an item which doesn't exist") );
-    wxCHECK_RET( item->IsCheckable(), wxT("attempt to check an uncheckable item") );
-
-    item->Check(check);
-}
-
-bool wxMenuBar::IsChecked(int id) const
-{
-    wxMenu *itemMenu = NULL;
-    wxMenuItem *item = FindItemForId(id, &itemMenu) ;
-
-    wxCHECK_MSG( item, FALSE, wxT("wxMenuBar::IsChecked(): no such item") );
-
-//    int flag = ::GetMenuState(GetHmenuOf(itemMenu), id, MF_BYCOMMAND);
-
-//    return (flag & MF_CHECKED) != 0;
-    return FALSE;
-}
-
-bool wxMenuBar::IsEnabled(int id) const
-{
-    wxMenu *itemMenu = NULL;
-    wxMenuItem *item = FindItemForId(id, &itemMenu) ;
-
-    wxCHECK_MSG( item, FALSE, wxT("wxMenuBar::IsEnabled(): no such item") );
-
-//    int flag = ::GetMenuState(GetHmenuOf(itemMenu), id, MF_BYCOMMAND) ;
-
-    // don't "and" with MF_ENABLED because its value is 0
-//    return (flag & MF_DISABLED) == 0;
-    return FALSE;
-}
-
-void wxMenuBar::SetLabel(int id, const wxString& label)
-{
-    wxMenu *itemMenu = NULL;
-    wxMenuItem *item = FindItemForId(id, &itemMenu) ;
-
-    wxCHECK_RET( item, wxT("wxMenuBar::SetLabel(): no such item") );
-
-    item->SetName(label);
-}
-
-wxString wxMenuBar::GetLabel(int id) const
-{
-    wxMenu *itemMenu = NULL;
-    wxMenuItem *item = FindItemForId(id, &itemMenu) ;
-
-    wxCHECK_MSG( item, wxT(""), wxT("wxMenuBar::GetLabel(): no such item") );
-
-    return item->GetName();
-}
-
-void wxMenuBar::SetHelpString (int id, const wxString& helpString)
-{
-    wxMenu *itemMenu = NULL;
-    wxMenuItem *item = FindItemForId(id, &itemMenu) ;
-
-    wxCHECK_RET( item, wxT("wxMenuBar::SetHelpString(): no such item") );
-
-    item->SetHelp(helpString);
-}
+            APIRET   rc;
+            ERRORID  vError;
+            wxString sError;
+            HWND     hSubMenu;
+
+            //
+            // Set the parent and owner of the submenues to be the menubar, not the desktop
+            //
+            hSubMenu = (*it)->m_vMenuData.hwndSubMenu;
+            if (!::WinSetParent((*it)->m_vMenuData.hwndSubMenu, m_hMenu, FALSE))
+            {
+                vError = ::WinGetLastError(vHabmain);
+                sError = wxPMErrorToStr(vError);
+                wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError.c_str());
+                return NULLHANDLE;
+            }
 
-wxString wxMenuBar::GetHelpString (int id) const
-{
-    wxMenu *itemMenu = NULL;
-    wxMenuItem *item = FindItemForId(id, &itemMenu) ;
+            if (!::WinSetOwner((*it)->m_vMenuData.hwndSubMenu, m_hMenu))
+            {
+                vError = ::WinGetLastError(vHabmain);
+                sError = wxPMErrorToStr(vError);
+                wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError.c_str());
+                return NULLHANDLE;
+            }
 
-    wxCHECK_MSG( item, wxT(""), wxT("wxMenuBar::GetHelpString(): no such item") );
+            (*it)->m_vMenuData.iPosition = (SHORT)i;
 
-    return item->GetHelp();
-}
+            rc = (APIRET)::WinSendMsg(m_hMenu, MM_INSERTITEM, (MPARAM)&(*it)->m_vMenuData, (MPARAM)m_titles[i].wx_str());
+            if (rc == (APIRET)MIT_MEMERROR || rc == (APIRET)MIT_ERROR)
+            {
+                vError = ::WinGetLastError(vHabmain);
+                sError = wxPMErrorToStr(vError);
+                wxLogError(wxT("Error inserting or appending a menuitem. Error: %s\n"), sError.c_str());
+                return NULLHANDLE;
+            }
+        }
+    }
+    return m_hMenu;
+} // end of wxMenuBar::Create
 
 // ---------------------------------------------------------------------------
 // wxMenuBar functions to work with the top level submenus
 // ---------------------------------------------------------------------------
 
+//
 // NB: we don't support owner drawn top level items for now, if we do these
 //     functions would have to be changed to use wxMenuItem as well
-
-void wxMenuBar::SetLabelTop(int pos, const wxString& label)
+//
+void wxMenuBar::EnableTop(
+  size_t                            nPos
+, bool                              bEnable
+)
 {
-    UINT id;
-    UINT flagsOld = 0; // TODO: ::GetMenuState((HMENU)m_hMenu, pos, MF_BYPOSITION);
-    if ( flagsOld == 0xFFFFFFFF )
-    {
-        wxLogLastError(wxT("GetMenuState"));
+    wxCHECK_RET(IsAttached(), wxT("doesn't work with unattached menubars"));
+    USHORT                          uFlag = 0;
+    SHORT                           nId;
+
+    if(!bEnable)
+       uFlag = MIA_DISABLED;
 
+    nId = SHORT1FROMMR(::WinSendMsg((HWND)m_hMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(nPos), (MPARAM)0));
+    if (nId == MIT_ERROR)
+    {
+        wxLogLastError(wxT("LogLastError"));
         return;
     }
+    ::WinSendMsg((HWND)m_hMenu, MM_SETITEMATTR, MPFROM2SHORT(nId, TRUE), MPFROM2SHORT(MIA_DISABLED, uFlag));
+    Refresh();
+} // end of wxMenuBar::EnableTop
 
-//    if ( flagsOld & MF_POPUP )
-//    {
-//        // HIBYTE contains the number of items in the submenu in this case
-//        flagsOld &= 0xff ;
-//        id = (UINT)::GetSubMenu((HMENU)m_hMenu, pos) ;
-//    }
-//    else
-//    {
-//        id = pos;
-//    }
-
-//    if ( ::ModifyMenu(GetHmenu(), pos, MF_BYPOSITION | MF_STRING | flagsOld,
-//                      id, label) == 0xFFFFFFFF )
-//    {
-//        wxLogLastError("ModifyMenu");
-//    }
-}
-
-wxString wxMenuBar::GetLabelTop(int pos) const
+void wxMenuBar::SetMenuLabel(
+  size_t                            nPos
+, const wxString&                   rLabel
+)
 {
-    int len = 0; // TODO: ::GetMenuString((HMENU)m_hMenu, pos, NULL, 0, MF_BYCOMMAND);
-
-    len++;  // for the NUL character
-    wxString label;
-//    ::GetMenuString(GetHmenu(), pos, label.GetWriteBuf(len), len, MF_BYCOMMAND);
-    label.UngetWriteBuf();
+    SHORT                           nId;
+    MENUITEM                        vItem;
 
-    return label;
-}
-
-// ---------------------------------------------------------------------------
-// wxMenuBar notifications
-// ---------------------------------------------------------------------------
-
-bool wxMenuBar::OnDelete(wxMenu *a_menu, int pos)
-{
-    if ( !m_menuBarFrame )
-        return TRUE;
+    wxCHECK_RET(nPos < GetMenuCount(), wxT("invalid menu index"));
+    m_titles[nPos] = rLabel;
 
-    // TODO
-/*
-    if ( ::RemoveMenu((HMENU)m_hMenu, (UINT)pos, MF_BYPOSITION) )
+    if (!IsAttached())
     {
-        // VZ: I'm not sure about what's going on here, so I leave an assert
-        wxASSERT_MSG( m_menus[pos] == a_menu, wxT("what is this parameter for??") );
-
-        a_menu->Detach();
-
-        if ( m_menuBarFrame )
-            Refresh();
+        return;
+    }
 
-        return TRUE;
+    nId = SHORT1FROMMR(::WinSendMsg((HWND)m_hMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(nPos), (MPARAM)0));
+    if (nId == MIT_ERROR)
+    {
+        wxLogLastError(wxT("LogLastError"));
+        return;
     }
-    else
+    if(!::WinSendMsg( (HWND)m_hMenu
+                     ,MM_QUERYITEM
+                     ,MPFROM2SHORT(nId, TRUE)
+                     ,MPARAM(&vItem)
+                    ))
     {
-        wxLogLastError("RemoveMenu");
+        wxLogLastError(wxT("QueryItem"));
     }
-*/
-    return FALSE;
-}
-
-bool wxMenuBar::OnAppend(wxMenu *a_menu, const wxChar *title)
-{
-    WXHMENU submenu = a_menu->GetHMenu();
-    if ( !submenu )
-        return FALSE;
-
-    if ( !m_menuBarFrame )
-        return TRUE;
-
-    a_menu->Attach(this);
-
-//    if ( !::AppendMenu(GetHmenu(), MF_POPUP | MF_STRING,
-//                       (UINT)submenu, title) )
-//    {
-//        wxLogLastError(wxT("AppendMenu"));
-//    }
+    nId = vItem.id;
 
+    if (::WinSendMsg(GetHmenu(), MM_SETITEMTEXT, MPFROMSHORT(nId), (MPARAM)rLabel.wx_str()));
+    {
+        wxLogLastError(wxT("ModifyMenu"));
+    }
     Refresh();
+} // end of wxMenuBar::SetMenuLabel
 
-    return TRUE;
-}
+wxString wxMenuBar::GetMenuLabel(
+  size_t                            nPos
+) const
+{
+    wxCHECK_MSG( nPos < GetMenuCount(), wxEmptyString,
+                 wxT("invalid menu index in wxMenuBar::GetMenuLabel") );
+    return m_titles[nPos];
+} // end of wxMenuBar::GetMenuLabel
 
 // ---------------------------------------------------------------------------
 // wxMenuBar construction
 // ---------------------------------------------------------------------------
-int wxMenuBar::FindMenu(const wxString& title)
+
+wxMenu* wxMenuBar::Replace(
+  size_t                             nPos
+, wxMenu*                            pMenu
+, const wxString&                    rTitle
+)
 {
-    wxString menuTitle = wxStripMenuCodes(title);
-    for ( int i = 0; i < m_menuCount; i++ )
+    SHORT                            nId;
+    wxString                         sTitle = wxPMTextToLabel(rTitle);
+    wxMenu*                          pMenuOld = wxMenuBarBase::Replace( nPos
+                                                                       ,pMenu
+                                                                       ,sTitle
+                                                                      );
+
+
+    nId = SHORT1FROMMR(::WinSendMsg((HWND)m_hMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(nPos), (MPARAM)0));
+    if (nId == MIT_ERROR)
     {
-        wxString title = wxStripMenuCodes(m_titles[i]);
-        if ( menuTitle == title )
-            return i;
+        wxLogLastError(wxT("LogLastError"));
+        return NULL;
     }
+    if (!pMenuOld)
+        return NULL;
+    m_titles[nPos] = sTitle;
+    if (IsAttached())
+    {
+        ::WinSendMsg((HWND)m_hMenu, MM_REMOVEITEM, MPFROM2SHORT(nId, TRUE), (MPARAM)0);
+        ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)sTitle.wx_str());
 
-    return wxNOT_FOUND;
+#if wxUSE_ACCEL
+        if (pMenuOld->HasAccels() || pMenu->HasAccels())
+        {
+            //
+            // Need to rebuild accell table
+            //
+            RebuildAccelTable();
+        }
+#endif // wxUSE_ACCEL
+        Refresh();
+    }
+    return pMenuOld;
+} // end of wxMenuBar::Replace
 
-}
+bool wxMenuBar::Insert( size_t          nPos,
+                        wxMenu*         pMenu,
+                        const wxString& rTitle )
+{
+    wxString sTitle = wxPMTextToLabel(rTitle);
 
+    if (!wxMenuBarBase::Insert( nPos, pMenu, sTitle ))
+        return false;
 
-void wxMenuBar::ReplaceMenu(int pos, wxMenu * new_menu, const wxString& title)
-{
-    if (m_menuBarFrame) return;
+    m_titles.Insert( sTitle, nPos );
 
-    if ( pos >= 0 && pos < m_menuCount )
+    if (IsAttached())
     {
-       wxMenu *old_menu = m_menus[pos];
-       m_menus[pos] = new_menu;
-       delete old_menu;
+        pMenu->m_vMenuData.iPosition = (SHORT)nPos;
+        ::WinSendMsg( (HWND)m_hMenu
+                     ,MM_INSERTITEM
+                     ,(MPARAM)&pMenu->m_vMenuData
+                     ,(MPARAM)sTitle.wx_str()
+                    );
+#if wxUSE_ACCEL
+        if (pMenu->HasAccels())
+        {
+            // need to rebuild accell table
+            RebuildAccelTable();
+        }
+#endif // wxUSE_ACCEL
+        Refresh();
     }
 
-}
-
+    return true;
+} // end of wxMenuBar::Insert
 
-void wxMenuBar::Insert(int pos, wxMenu * menu, const wxString& title)
+bool wxMenuBar::Append( wxMenu* pMenu,
+                        const wxString& rsTitle )
 {
-    if (m_menuBarFrame) return;
-    if ( pos < 0 && pos >= m_menuCount ) return;
+    WXHMENU hSubmenu = pMenu ? pMenu->GetHMenu() : 0;
 
-    m_menuCount ++;
-    wxMenu **new_menus = new wxMenu *[m_menuCount];
-    wxString *new_titles = new wxString[m_menuCount];
-    int i;
+    wxCHECK_MSG(hSubmenu, false, wxT("can't append invalid menu to menubar"));
 
-    for (i = 0; i < pos; i++)
-    {
-        new_menus[i] = m_menus[i];
-        m_menus[i] = NULL;
-        new_titles[i] = m_titles[i];
-        m_titles[i] = wxT("");
-    }
+    wxString sTitle = wxPMTextToLabel(rsTitle);
 
-    new_menus[pos] = (wxMenu *)menu;
-    new_titles[i] = title;
+    if (!wxMenuBarBase::Append(pMenu, sTitle))
+        return false;
 
-    for (i = pos+1; i < m_menuCount; i++)
-    {
-        new_menus[i] = m_menus[i-1];
-        m_menus[i-1] = NULL;
-        new_titles[i] = m_titles[i-1];
-        m_titles[i-1] = wxT("");
-    }
-    if (m_menus)
+    m_titles.Add(sTitle);
+
+    if ( IsAttached() )
     {
-        delete[]m_menus;
-        delete[]m_titles;
+        pMenu->m_vMenuData.iPosition = MIT_END;
+        ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)sTitle.wx_str());
+#if wxUSE_ACCEL
+        if (pMenu->HasAccels())
+        {
+            //
+            // Need to rebuild accell table
+            //
+            RebuildAccelTable();
+        }
+#endif // wxUSE_ACCEL
+        Refresh();
     }
-    m_menus = new_menus;
-    m_titles = new_titles;
-
-    menu->SetParent(this);
-
-}
+    return true;
+} // end of wxMenuBar::Append
 
-
-void wxMenuBar::Append (wxMenu * menu, const wxString& title)
+wxMenu* wxMenuBar::Remove(
+  size_t                            nPos
+)
 {
-    if (!OnAppend(menu, title))
-        return;
-
-    m_menuCount ++;
-    wxMenu **new_menus = new wxMenu *[m_menuCount];
-    wxString *new_titles = new wxString[m_menuCount];
-    int i;
-
-    for (i = 0; i < m_menuCount - 1; i++)
+    wxMenu*                         pMenu = wxMenuBarBase::Remove(nPos);
+    SHORT                           nId;
+
+    if (!pMenu)
+        return NULL;
+
+    nId = SHORT1FROMMR(::WinSendMsg( (HWND)GetHmenu()
+                                    ,MM_ITEMIDFROMPOSITION
+                                    ,MPFROMSHORT(nPos)
+                                    ,(MPARAM)0)
+                                   );
+    if (nId == MIT_ERROR)
     {
-        new_menus[i] = m_menus[i];
-        m_menus[i] = NULL;
-        new_titles[i] = m_titles[i];
-        m_titles[i] = wxT("");
+        wxLogLastError(wxT("LogLastError"));
+        return NULL;
     }
-    if (m_menus)
+    if (IsAttached())
     {
-        delete[]m_menus;
-        delete[]m_titles;
-    }
-    m_menus = new_menus;
-    m_titles = new_titles;
+        ::WinSendMsg( (HWND)GetHmenu()
+                     ,MM_REMOVEITEM
+                     ,MPFROM2SHORT(nId, TRUE)
+                     ,(MPARAM)0
+                    );
 
-    m_menus[m_menuCount - 1] = (wxMenu *)menu;
-    m_titles[m_menuCount - 1] = title;
-
-    menu->SetParent(this);
-}
-
-void wxMenuBar::Delete(wxMenu * menu, int i)
-{
-    int j;
-    int ii = (int) i;
-
-    if (menu != 0) {
-        for (ii = 0; ii < m_menuCount; ii++) {
-            if (m_menus[ii] == menu)
-                break;
+#if wxUSE_ACCEL
+        if (pMenu->HasAccels())
+        {
+            //
+            // Need to rebuild accell table
+            //
+            RebuildAccelTable();
         }
-        if (ii >= m_menuCount)
-            return;
-    } else {
-        if (ii < 0 || ii >= m_menuCount)
-            return;
-        menu = m_menus[ii];
+#endif // wxUSE_ACCEL
+        Refresh();
     }
+    m_titles.RemoveAt(nPos);
+    return pMenu;
+} // end of wxMenuBar::Remove
 
-    if (!OnDelete(menu, ii))
-        return;
-
-    menu->SetParent(NULL);
-
-    -- m_menuCount;
-    for (j = ii; j < m_menuCount; j++) {
-        m_menus[j] = m_menus[j + 1];
-        m_titles[j] = m_titles[j + 1];
-    }
-}
+#if wxUSE_ACCEL
 
-void wxMenuBar::Attach(wxFrame *frame)
+void wxMenuBar::RebuildAccelTable()
 {
-    wxASSERT_MSG( !m_menuBarFrame, wxT("menubar already attached!") );
-
-    m_menuBarFrame = frame;
-
-#if wxUSE_ACCEL
-    // create the accel table - we consider that the menubar construction is
-    // finished
-    size_t nAccelCount = 0;
-    int i;
-    for ( i = 0; i < m_menuCount; i++ )
+    //
+    // Merge the accelerators of all menus into one accel table
+    //
+    size_t                          nAccelCount = 0;
+    size_t                          i;
+    size_t                          nCount = GetMenuCount();
+    wxMenuList::iterator it;
+    for (i = 0, it = m_menus.begin(); i < nCount; i++, it++)
     {
-        nAccelCount += m_menus[i]->GetAccelCount();
+        nAccelCount += (*it)->GetAccelCount();
     }
 
-    if ( nAccelCount )
+    if (nAccelCount)
     {
-        wxAcceleratorEntry *accelEntries = new wxAcceleratorEntry[nAccelCount];
+        wxAcceleratorEntry*         pAccelEntries = new wxAcceleratorEntry[nAccelCount];
 
         nAccelCount = 0;
-        for ( i = 0; i < m_menuCount; i++ )
+        for (i = 0, it = m_menus.begin(); i < nCount; i++, it++)
         {
-            nAccelCount += m_menus[i]->CopyAccels(&accelEntries[nAccelCount]);
+            nAccelCount += (*it)->CopyAccels(&pAccelEntries[nAccelCount]);
         }
+        m_vAccelTable = wxAcceleratorTable( nAccelCount
+                                           ,pAccelEntries
+                                          );
+        delete [] pAccelEntries;
+    }
+} // end of wxMenuBar::RebuildAccelTable
 
-        m_accelTable = wxAcceleratorTable(nAccelCount, accelEntries);
+#endif // wxUSE_ACCEL
+
+void wxMenuBar::Attach(
+  wxFrame*                          pFrame
+)
+{
+    wxMenuBarBase::Attach(pFrame);
 
-        delete [] accelEntries;
+#if wxUSE_ACCEL
+    RebuildAccelTable();
+    //
+    // Ensure the accelerator table is set to the frame (not the client!)
+    //
+    if (!::WinSetAccelTable( vHabmain
+                            ,m_vAccelTable.GetHACCEL()
+                            ,(HWND)pFrame->GetFrame()
+                           ))
+    {
+        wxLogLastError(wxT("WinSetAccelTable"));
     }
 #endif // wxUSE_ACCEL
-}
+} // end of wxMenuBar::Attach
 
 void wxMenuBar::Detach()
 {
-//    ::DestroyMenu((HMENU)m_hMenu);
-    m_hMenu = NULL;
+    ::WinDestroyWindow((HWND)m_hMenu);
+    m_hMenu = (WXHMENU)NULL;
     m_menuBarFrame = NULL;
-}
-
+} // end of wxMenuBar::Detach
 
 // ---------------------------------------------------------------------------
 // wxMenuBar searching for menu items
 // ---------------------------------------------------------------------------
 
+//
 // Find the itemString in menuString, and return the item id or wxNOT_FOUND
-int wxMenuBar::FindMenuItem(const wxString& menuString,
-                            const wxString& itemString) const
+//
+int wxMenuBar::FindMenuItem(
+  const wxString&                   rMenuString
+, const wxString&                   rItemString
+) const
 {
-    wxString menuLabel = wxStripMenuCodes(menuString);
-    for ( int i = 0; i < m_menuCount; i++ )
+    wxString                        sMenuLabel = wxStripMenuCodes(rMenuString);
+    size_t                          nCount = GetMenuCount(), i;
+    wxMenuList::const_iterator it;
+    for (i = 0, it = m_menus.begin(); i < nCount; i++, it++)
     {
-        wxString title = wxStripMenuCodes(m_titles[i]);
-        if ( menuString == title )
-            return m_menus[i]->FindItem(itemString);
-    }
+        wxString                    sTitle = wxStripMenuCodes(m_titles[i]);
 
+        if (rMenuString == sTitle)
+            return (*it)->FindItem(rItemString);
+    }
     return wxNOT_FOUND;
-}
+} // end of wxMenuBar::FindMenuItem
 
-wxMenuItem *wxMenuBar::FindItemForId (int id, wxMenu **itemMenu) const
+wxMenuItem* wxMenuBar::FindItem(
+  int                               nId
+, wxMenu**                          ppItemMenu
+) const
 {
-    if ( itemMenu )
-        *itemMenu = NULL;
+    if (ppItemMenu)
+        *ppItemMenu = NULL;
 
-    wxMenuItem *item = NULL;
-    for ( int i = 0; !item && (i < m_menuCount); i++ )
+    wxMenuItem*                     pItem = NULL;
+    size_t                          nCount = GetMenuCount(), i;
+    wxMenuList::const_iterator it;
+    for (i = 0, it = m_menus.begin(); !pItem && (i < nCount); i++, it++)
     {
-        item = m_menus[i]->FindItemForId(id, itemMenu);
+        pItem = (*it)->FindItem( nId
+                                ,ppItemMenu
+                               );
     }
-
-    return item;
-}
-
-
-// ----------------------------------------------------------------------------
-// helper functions
-// ----------------------------------------------------------------------------
-
-wxWindow *wxMenu::GetWindow() const
+    return pItem;
+} // end of wxMenuBar::FindItem
+
+wxMenuItem* wxMenuBar::FindItem(
+  int                               nId
+, ULONG                             hItem
+, wxMenu**                          ppItemMenu
+) const
 {
-    if ( m_pInvokingWindow != NULL )
-        return m_pInvokingWindow;
-    else if ( m_menuBar != NULL)
-        return m_menuBar->GetFrame();
-
-    return NULL;
-}
-
-WXHMENU wxMenu::GetHMenu() const
-{
-    if ( m_hMenu != 0 )
-        return m_hMenu;
-    else if ( m_savehMenu != 0 )
-        return m_savehMenu;
+    if (ppItemMenu)
+        *ppItemMenu = NULL;
 
-    wxFAIL_MSG(wxT("wxMenu without HMENU"));
-
-    return 0;
-}
-
-// Update a menu and all submenus recursively. source is the object that has
-// the update event handlers defined for it. If NULL, the menu or associated
-// window will be used.
-void wxMenu::UpdateUI(wxEvtHandler* source)
-{
-    if (!source && GetInvokingWindow())
-        source = GetInvokingWindow()->GetEventHandler();
-    if (!source)
-        source = GetEventHandler();
-    if (!source)
-        source = this;
-
-    wxNode* node = GetItems().First();
-    while (node)
+    wxMenuItem*                     pItem = NULL;
+    size_t                          nCount = GetMenuCount(), i;
+    wxMenuList::const_iterator it;
+    for (i = 0, it = m_menus.begin(); !pItem && (i < nCount); i++, it++)
     {
-        wxMenuItem* item = (wxMenuItem*) node->Data();
-        if ( !item->IsSeparator() )
-        {
-            wxWindowID id = item->GetId();
-            wxUpdateUIEvent event(id);
-            event.SetEventObject( source );
-
-            if (source->ProcessEvent(event))
-            {
-                if (event.GetSetText())
-                    SetLabel(id, event.GetText());
-                if (event.GetSetChecked())
-                    Check(id, event.GetChecked());
-                if (event.GetSetEnabled())
-                    Enable(id, event.GetEnabled());
-            }
-
-            if (item->GetSubMenu())
-                item->GetSubMenu()->UpdateUI(source);
-        }
-        node = node->Next();
+        pItem = (*it)->FindItem( nId
+                                ,hItem
+                                ,ppItemMenu
+                               );
     }
-}
-
+    return pItem;
+} // end of wxMenuBar::FindItem