- if (bCheck)
- bOk = ::WinSendMsg( GetHMenuOf(m_parentMenu)
- ,MM_SETITEMATTR
- ,MPFROM2SHORT(GetRealId(), TRUE)
- ,MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED)
- );
- else
- bOk = ::WinSendMsg( GetHMenuOf(m_parentMenu)
- ,MM_SETITEMATTR
- ,MPFROM2SHORT(GetRealId(), TRUE)
- ,MPFROM2SHORT(MIA_CHECKED, FALSE)
- );
+
+ HMENU hMenu = GetHmenuOf(m_parentMenu);
+
+ if ( GetKind() == wxITEM_RADIO )
+ {
+ //
+ // It doesn't make sense to uncheck a radio item - what would this do?
+ //
+ if (!bCheck)
+ return;
+
+ //
+ // Get the index of this item in the menu
+ //
+ const wxMenuItemList& rItems = m_parentMenu->GetMenuItems();
+ int nPos = rItems.IndexOf(this);
+ int nStart;
+ int nEnd;
+
+ wxCHECK_RET( nPos != wxNOT_FOUND,
+ _T("menuitem not found in the menu items list?") );
+
+ //
+ // Get the radio group range
+ //
+
+ if (m_bIsRadioGroupStart)
+ {
+ // we already have all information we need
+ nStart = nPos;
+ nEnd = m_vRadioGroup.m_nEnd;
+ }
+ else // Next radio group item
+ {
+ //
+ // Get the radio group end from the start item
+ //
+ nStart = m_vRadioGroup.m_nStart;
+ nEnd = rItems.Item(nStart)->GetData()->m_vRadioGroup.m_nEnd;
+ }
+
+ //
+ // Also uncheck all the other items in this radio group
+ //
+ wxMenuItemList::Node* pNode = rItems.Item(nStart);
+
+ for (int n = nStart; n <= nEnd && pNode; n++)
+ {
+ if (n != nPos)
+ {
+ pNode->GetData()->m_isChecked = FALSE;
+ }
+
+ if (n == nPos)
+ {
+ bOk = (bool)::WinSendMsg( hMenu
+ ,MM_SETITEMATTR
+ ,MPFROM2SHORT(n, TRUE)
+ ,MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED)
+ );
+ }
+ else
+ {
+ bOk = (bool)::WinSendMsg( hMenu
+ ,MM_SETITEMATTR
+ ,MPFROM2SHORT(n, TRUE)
+ ,MPFROM2SHORT(MIA_CHECKED, FALSE)
+ );
+ }
+ pNode = pNode->GetNext();
+ }
+ }
+ else // check item
+ {
+ if (bCheck)
+ bOk = (bool)::WinSendMsg( hMenu
+ ,MM_SETITEMATTR
+ ,MPFROM2SHORT(GetRealId(), TRUE)
+ ,MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED)
+ );
+ else
+ bOk = (bool)::WinSendMsg( hMenu
+ ,MM_SETITEMATTR
+ ,MPFROM2SHORT(GetRealId(), TRUE)
+ ,MPFROM2SHORT(MIA_CHECKED, FALSE)
+ );
+ }