X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/893758d507abf66a429666b9f0b2c1baa195b398..4b04699b670b4ab4632229fa0264d154acd3bec1:/src/os2/menu.cpp?ds=sidebyside diff --git a/src/os2/menu.cpp b/src/os2/menu.cpp index 186744bf97..37898a1e55 100644 --- a/src/os2/menu.cpp +++ b/src/os2/menu.cpp @@ -73,7 +73,7 @@ static wxString TextToLabel(const wxString& rTitle) { wxString Title; const wxChar *pc; - for (pc = rTitle; *pc != wxT('\0'); pc++ ) + for (pc = rTitle.c_str(); *pc != wxT('\0'); pc++ ) { if (*pc == wxT('&') ) { @@ -85,10 +85,6 @@ static wxString TextToLabel(const wxString& rTitle) else Title << wxT('~'); } -// else if (*pc == wxT('/')) -// { -// Title << wxT('\\'); -// } else { if ( *pc == wxT('~') ) @@ -155,6 +151,9 @@ void wxMenu::Init() ); AppendSeparator(); } + for (int i = 0; i < 128; i++) + m_vAccels[i] = NULL; + m_nNextAccel = 0; } // end of wxMenu::Init // @@ -179,7 +178,15 @@ wxMenu::~wxMenu() // Delete accels // #if (!(defined(__VISAGECPP__) && (__IBMCPP__ < 400 || __IBMC__ < 400 ))) - WX_CLEAR_ARRAY(m_vAccels); + for (int i = 0; i < 128; i++) + { + if (m_vAccels[i]) + { + delete m_vAccels[i]; + m_vAccels[i] = NULL; + } + } +// WX_CLEAR_ARRAY(m_vAccels); #endif #endif // wxUSE_ACCEL } // end of wxMenu::~wxMenu @@ -192,17 +199,28 @@ void wxMenu::Break() #if wxUSE_ACCEL +void wxMenu::EndRadioGroup() +{ + // + // We're not inside a radio group any longer + // + m_nStartRadioGroup = -1; +} // end of wxMenu::EndRadioGroup + int wxMenu::FindAccel( int nId ) const { size_t n; - size_t nCount = m_vAccels.GetCount(); +// size_t nCount = m_vAccels.GetCount(); - for (n = 0; n < nCount; n++) + for (n = 0; n < m_nNextAccel; n++) { - if (m_vAccels[n]->m_command == nId) - return n; + if (m_vAccels[n] != NULL) + { + if (m_vAccels[n]->m_command == nId) + return n; + } } return wxNOT_FOUND; } // end of wxMenu::FindAccel @@ -211,45 +229,65 @@ void wxMenu::UpdateAccel( wxMenuItem* pItem ) { - // - // Find the (new) accel for this item - // - wxAcceleratorEntry* pAccel = wxGetAccelFromString(pItem->GetText()); - - if (pAccel) - pAccel->m_command = pItem->GetId(); - - // - // Find the old one - // - int n = FindAccel(pItem->GetId()); + if (pItem->IsSubMenu()) + { + wxMenu* pSubmenu = pItem->GetSubMenu(); + wxMenuItemList::Node* pNode = pSubmenu->GetMenuItems().GetFirst(); - if (n == wxNOT_FOUND) + while (pNode) + { + UpdateAccel(pNode->GetData()); + pNode = pNode->GetNext(); + } + } + else if (!pItem->IsSeparator()) { // - // No old, add new if any + // Find the (new) accel for this item // + wxAcceleratorEntry* pAccel = wxGetAccelFromString(pItem->GetText()); if (pAccel) - m_vAccels.Add(pAccel); - else - return; // skipping RebuildAccelTable() below - } - else - { + pAccel->m_command = pItem->GetId(); + // - // Replace old with new or just remove the old one if no new + // Find the old one // - delete m_vAccels[n]; + size_t n = FindAccel(pItem->GetId()); - if (pAccel) - m_vAccels[n] = pAccel; + if (n == wxNOT_FOUND) + { + // + // No old, add new if any + // + if (pAccel) + { + if (m_nNextAccel < 128) + { + m_vAccels[m_nNextAccel] = pAccel; + m_nNextAccel++; + } + else + return; // skipping RebuildAccelTable() below + } + else + return; // skipping RebuildAccelTable() below + } else - m_vAccels.RemoveAt(n); - } + { + // + // Replace old with new or just remove the old one if no new + // + delete m_vAccels[n]; + m_vAccels[n] = NULL; - if (IsAttached()) - { - m_menuBar->RebuildAccelTable(); + if (pAccel) + m_vAccels[n] = pAccel; + } + + if (IsAttached()) + { + m_menuBar->RebuildAccelTable(); + } } } // wxMenu::UpdateAccel @@ -263,6 +301,10 @@ bool wxMenu::DoInsertOrAppend( , size_t nPos ) { + wxMenu* pSubmenu = pItem->GetSubMenu(); + MENUITEM& rItem = (pSubmenu != NULL)?pSubmenu->m_vMenuData: + pItem->m_vMenuData; + ERRORID vError; wxString sError; char zMsg[128]; @@ -275,9 +317,6 @@ bool wxMenu::DoInsertOrAppend( // MENUITEM for submenus as required by ::MM_INSERTITEM message API // - wxMenu* pSubmenu = pItem->GetSubMenu(); - MENUITEM& rItem = (pSubmenu != NULL)?pSubmenu->m_vMenuData: - pItem->m_vMenuData; if(pSubmenu != NULL) { wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu")); @@ -402,8 +441,64 @@ bool wxMenu::DoAppend( wxMenuItem* pItem ) { - return wxMenuBase::DoAppend(pItem) && DoInsertOrAppend(pItem); -} + wxCHECK_MSG( pItem, FALSE, _T("NULL item in wxMenu::DoAppend") ); + + bool bCheck = FALSE; + + if (pItem->GetKind() == wxITEM_RADIO) + { + int nCount = GetMenuItemCount(); + + 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); + wxMenuItemList::Node* pNode = GetMenuItems().Item(m_nStartRadioGroup); + + if (pNode) + { + pNode->GetData()->SetRadioGroupEnd(nCount); + } + else + { + wxFAIL_MSG( _T("where is the radio group start item?") ); + } + } + } + else // not a radio item + { + EndRadioGroup(); + } + if (!wxMenuBase::DoAppend(pItem) || !DoInsertOrAppend(pItem)) + { + return FALSE; + } + if (bCheck) + { + pItem->Check(TRUE); + } + return TRUE; +} // end of wxMenu::DoInsert bool wxMenu::DoInsert( size_t nPos @@ -448,7 +543,7 @@ wxMenuItem* wxMenu::DoRemove( if (n != wxNOT_FOUND) { delete m_vAccels[n]; - m_vAccels.RemoveAt(n); + m_vAccels[n] = NULL; } #endif // wxUSE_ACCEL @@ -609,7 +704,12 @@ wxMenuItem* wxMenu::FindItem( } else if ( pItem->IsSubMenu() ) { - pItem = pItem->GetSubMenu()->FindItem(nItemId, hItem, ppItemMenu); + pItem = pItem->GetSubMenu()->FindItem( nItemId + ,hItem + ,ppItemMenu + ); + if (pItem) + break; } else { @@ -627,7 +727,7 @@ wxMenuItem* wxMenu::FindItem( void wxMenuBar::Init() { m_eventHandler = this; - m_pMenuBarFrame = NULL; + m_menuBarFrame = NULL; m_hMenu = 0; } // end of wxMenuBar::Init @@ -672,7 +772,7 @@ void wxMenuBar::Refresh() { wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") ); - WinSendMsg(GetWinHwnd(m_pMenuBarFrame), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); + WinSendMsg(GetWinHwnd(m_menuBarFrame), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); } // end of wxMenuBar::Refresh WXHMENU wxMenuBar::Create() @@ -688,8 +788,8 @@ WXHMENU wxMenuBar::Create() // // Menubars should be associated with a frame otherwise they are popups // - if (m_pMenuBarFrame != NULL) - hFrame = GetWinHwnd(m_pMenuBarFrame); + if (m_menuBarFrame != NULL) + hFrame = GetWinHwnd(m_menuBarFrame); else hFrame = HWND_DESKTOP; // @@ -899,8 +999,6 @@ bool wxMenuBar::Insert( ,nPos ); - pMenu->Attach(this); - if (IsAttached()) { ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)Title.c_str()); @@ -929,7 +1027,6 @@ bool wxMenuBar::Append( if (!wxMenuBarBase::Append(pMenu, Title)) return FALSE; - pMenu->Attach(this); m_titles.Add(Title); if ( IsAttached() ) @@ -969,7 +1066,6 @@ wxMenu* wxMenuBar::Remove( if (IsAttached()) { ::WinSendMsg((HWND)GetHmenu(), MM_REMOVEITEM, MPFROM2SHORT(nId, TRUE), (MPARAM)0); - pMenu->Detach(); #if wxUSE_ACCEL if (pMenu->HasAccels()) @@ -1025,7 +1121,6 @@ void wxMenuBar::Attach( ) { wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") ); - m_pMenuBarFrame = pFrame; #if wxUSE_ACCEL RebuildAccelTable(); @@ -1044,7 +1139,7 @@ void wxMenuBar::Detach() { ::WinDestroyWindow((HWND)m_hMenu); m_hMenu = (WXHMENU)NULL; - m_pMenuBarFrame = NULL; + m_menuBarFrame = NULL; } // end of wxMenuBar::Detach // ---------------------------------------------------------------------------