Fix the position calculating of insert a radio menu item
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77795 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -52,6 +52,8 @@ public:
|
|||||||
void SetAsRadioGroupStart();
|
void SetAsRadioGroupStart();
|
||||||
void SetRadioGroupStart(int start);
|
void SetRadioGroupStart(int start);
|
||||||
void SetRadioGroupEnd(int end);
|
void SetRadioGroupEnd(int end);
|
||||||
|
int GetRadioGroupStart();
|
||||||
|
int GetRadioGroupEnd();
|
||||||
|
|
||||||
// wxUniv-specific methods for implementation only starting from here
|
// wxUniv-specific methods for implementation only starting from here
|
||||||
|
|
||||||
|
@@ -1160,8 +1160,61 @@ wxMenuItem* wxMenu::DoAppend(wxMenuItem *item)
|
|||||||
|
|
||||||
wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
|
wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
|
||||||
{
|
{
|
||||||
if ( !wxMenuBase::DoInsert(pos, item) )
|
if ( item->GetKind() == wxITEM_RADIO )
|
||||||
return NULL;
|
{
|
||||||
|
unsigned int start, end;
|
||||||
|
wxMenuItemIter firstRadio;
|
||||||
|
|
||||||
|
if ( m_startRadioGroup == -1 )
|
||||||
|
{
|
||||||
|
// start a new radio group
|
||||||
|
m_startRadioGroup = pos;
|
||||||
|
|
||||||
|
// set this element as the first of radio group
|
||||||
|
item->SetAsRadioGroupStart();
|
||||||
|
item->SetRadioGroupEnd(m_startRadioGroup);
|
||||||
|
wxMenuBase::DoInsert(pos, item);
|
||||||
|
item->Check(true);
|
||||||
|
}
|
||||||
|
else // extend the current radio group
|
||||||
|
{
|
||||||
|
// get current first radio item in radio group
|
||||||
|
firstRadio = GetMenuItems().Item(m_startRadioGroup);
|
||||||
|
|
||||||
|
// get current radio group range
|
||||||
|
start = firstRadio->GetData()->GetRadioGroupStart();
|
||||||
|
end = firstRadio->GetData()->GetRadioGroupEnd();
|
||||||
|
|
||||||
|
if ( pos <= start )
|
||||||
|
{
|
||||||
|
// Item is inserted in the begining of the range
|
||||||
|
// we need to update its end item
|
||||||
|
m_startRadioGroup = pos;
|
||||||
|
item->SetAsRadioGroupStart();
|
||||||
|
item->SetRadioGroupEnd(end + 1);
|
||||||
|
}
|
||||||
|
else if ( (pos >= start) && (pos <= end) )
|
||||||
|
{
|
||||||
|
// we need to update its end item
|
||||||
|
item->SetRadioGroupStart(m_startRadioGroup);
|
||||||
|
|
||||||
|
// Item is inserted in the middle of this range or immediately
|
||||||
|
// after it in which case it extends this range so make it span
|
||||||
|
// one more item in any case.
|
||||||
|
if ( firstRadio )
|
||||||
|
{
|
||||||
|
firstRadio->GetData()->SetRadioGroupEnd(end + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxFAIL_MSG( wxT("where is the radio group start item?") );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wxMenuBase::DoInsert(pos, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
wxMenuBase::DoInsert(pos, item);
|
||||||
|
|
||||||
OnItemAdded(item);
|
OnItemAdded(item);
|
||||||
|
|
||||||
@@ -1605,6 +1658,16 @@ void wxMenuItem::SetRadioGroupEnd(int end)
|
|||||||
m_radioGroup.end = end;
|
m_radioGroup.end = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int wxMenuItem::GetRadioGroupStart()
|
||||||
|
{
|
||||||
|
return m_radioGroup.start;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxMenuItem::GetRadioGroupEnd()
|
||||||
|
{
|
||||||
|
return m_radioGroup.end;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxMenuBar creation
|
// wxMenuBar creation
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user