- if (bCheck)
- bOk = (bool)::WinSendMsg( GetHMenuOf(m_parentMenu)
- ,MM_SETITEMATTR
- ,MPFROM2SHORT(GetRealId(), TRUE)
- ,MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED)
- );
- else
- bOk = (bool)::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);
+
+ wxCHECK_RET( nPos != wxNOT_FOUND
+ ,_T("menuitem not found in the menu items list?")
+ );
+
+ //
+ // Get the radio group range
+ //
+ int nStart;
+ int nEnd;
+
+ 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::compatibility_iterator node = rItems.Item(nStart);
+
+ for (int n = nStart; n <= nEnd && node; n++)
+ {
+ if (n == nPos)
+ {
+ ::WinSendMsg( hMenu
+ ,MM_SETITEMATTR
+ ,MPFROM2SHORT(n, TRUE)
+ ,MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED)
+ );
+ }
+ if (n != nPos)
+ {
+ node->GetData()->m_isChecked = FALSE;
+ ::WinSendMsg( hMenu
+ ,MM_SETITEMATTR
+ ,MPFROM2SHORT(n, TRUE)
+ ,MPFROM2SHORT(MIA_CHECKED, FALSE)
+ );
+ }
+ node = node->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)
+ );
+ }