+ // See if we need to create a new radio group for this item or
+ // add it to an existing one.
+ wxMenuItem* radioGroupItem = NULL;
+
+ const size_t numItems = GetMenuItemCount();
+ const size_t n = pos == -1 ? numItems - 1 : size_t(pos);
+
+ if (n != 0)
+ {
+ wxMenuItem* const itemPrev = FindItemByPosition(n - 1);
+ if ( itemPrev->GetKind() == wxITEM_RADIO )
+ {
+ // Appending an item after an existing radio item puts
+ // it into the same radio group.
+ radioGroupItem = itemPrev;
+ }
+ }
+
+ if (radioGroupItem == NULL && n != numItems - 1)
+ {
+ wxMenuItem* const itemNext = FindItemByPosition(n + 1);
+ if ( itemNext->GetKind() == wxITEM_RADIO )
+ {
+ // Inserting an item before an existing radio item
+ // also puts it into the existing radio group.
+ radioGroupItem = itemNext;
+ }
+ }
+