- Str255 label;
- wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false);
- AppendMenu( m_macPopUpMenuHandle , label ) ;
- m_strings.Add( item ) ;
- m_datas.Add( NULL ) ;
- int index = m_strings.GetCount() - 1 ;
- DoSetItemClientData( index , NULL ) ;
- SetControlMaximum( m_macControl , GetCount()) ;
- return index ;
+#if wxUSE_STL
+ wxArrayString::iterator insertPoint;
+ size_t index;
+
+ if (GetWindowStyle() & wxCB_SORT)
+ {
+ insertPoint = std::lower_bound( m_strings.begin(), m_strings.end(), item );
+ index = insertPoint - m_strings.begin();
+ }
+ else
+ {
+ insertPoint = m_strings.end();
+ index = m_strings.size();
+ }
+
+ m_strings.insert( insertPoint, item );
+#else
+ size_t index = m_strings.Add( item ) ;
+#endif
+ m_datas.Insert( NULL , index ) ;
+ UMAInsertMenuItem(MAC_WXHMENU( m_macPopUpMenuHandle ) , item, m_font.GetEncoding() , index );
+ DoSetItemClientData( index , NULL ) ;
+ m_peer->SetMaximum( GetCount() ) ;
+ return index ;
+}
+
+int wxChoice::DoInsert(const wxString& item, int pos)
+{
+ wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
+ wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
+
+ if (pos == GetCount())
+ return DoAppend(item);
+
+ UMAInsertMenuItem(MAC_WXHMENU( m_macPopUpMenuHandle ) , item, m_font.GetEncoding() , pos );
+ m_strings.Insert( item, pos ) ;
+ m_datas.Insert( NULL, pos ) ;
+ DoSetItemClientData( pos , NULL ) ;
+ m_peer->SetMaximum( GetCount() ) ;
+ return pos ;