Insert() patch from John Labenski
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20564 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -102,7 +102,7 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id,
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
GtkAppendHelper(menu, choices[i]);
|
||||
GtkAddHelper(menu, i, choices[i]);
|
||||
}
|
||||
|
||||
gtk_option_menu_set_menu( GTK_OPTION_MENU(m_widget), menu );
|
||||
@@ -136,7 +136,20 @@ int wxChoice::DoAppend( const wxString &item )
|
||||
|
||||
GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
|
||||
|
||||
return GtkAppendHelper(menu, item);
|
||||
return GtkAddHelper(menu, GetCount(), item);
|
||||
}
|
||||
|
||||
int wxChoice::DoInsert( const wxString &item, int pos )
|
||||
{
|
||||
wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice control") );
|
||||
wxCHECK_MSG( (pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
if (pos == GetCount())
|
||||
return DoAppend(item);
|
||||
|
||||
GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
|
||||
|
||||
return GtkAddHelper(menu, pos, item);
|
||||
}
|
||||
|
||||
void wxChoice::DoSetItemClientData( int n, void* clientData )
|
||||
@@ -388,8 +401,10 @@ void wxChoice::ApplyWidgetStyle()
|
||||
}
|
||||
}
|
||||
|
||||
size_t wxChoice::GtkAppendHelper(GtkWidget *menu, const wxString& item)
|
||||
int wxChoice::GtkAddHelper(GtkWidget *menu, int pos, const wxString& item)
|
||||
{
|
||||
wxCHECK_MSG((pos>=0) && (pos<=(int)m_clientList.GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
GtkWidget *menu_item = gtk_menu_item_new_with_label( wxGTK_CONV( item ) );
|
||||
|
||||
size_t index;
|
||||
@@ -412,14 +427,22 @@ size_t wxChoice::GtkAppendHelper(GtkWidget *menu, const wxString& item)
|
||||
}
|
||||
else
|
||||
{
|
||||
// normal control, just append
|
||||
gtk_menu_append( GTK_MENU(menu), menu_item );
|
||||
|
||||
m_clientList.Append( (wxObject*) NULL );
|
||||
|
||||
// don't call wxChoice::GetCount() from here because it doesn't work
|
||||
// if we're called from ctor (and GtkMenuShell is still NULL)
|
||||
|
||||
// normal control, just append
|
||||
if (pos == (int)m_clientList.GetCount())
|
||||
{
|
||||
gtk_menu_append( GTK_MENU(menu), menu_item );
|
||||
m_clientList.Append( (wxObject*) NULL );
|
||||
index = m_clientList.GetCount() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_menu_insert( GTK_MENU(menu), menu_item, pos );
|
||||
m_clientList.Insert( pos, (wxObject*) NULL );
|
||||
index = pos;
|
||||
}
|
||||
}
|
||||
|
||||
if (GTK_WIDGET_REALIZED(m_widget))
|
||||
|
@@ -269,6 +269,93 @@ void wxComboBox::Append( const wxString &item, wxClientData *clientData )
|
||||
AppendCommon( item );
|
||||
}
|
||||
|
||||
void wxComboBox::InsertCommon( const wxString &item, int pos )
|
||||
{
|
||||
wxCHECK_RET(!(GetWindowStyle() & wxCB_SORT), wxT("can't insert into sorted list"));
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
|
||||
|
||||
int count = GetCount();
|
||||
wxCHECK_RET((pos>=0) && (pos<=count), wxT("invalid index"));
|
||||
if (pos == count)
|
||||
{
|
||||
AppendCommon(item);
|
||||
return;
|
||||
}
|
||||
|
||||
DisableEvents();
|
||||
|
||||
GtkWidget *list = GTK_COMBO(m_widget)->list;
|
||||
|
||||
GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
|
||||
|
||||
GList *gitem_list = g_list_alloc ();
|
||||
gitem_list->data = list_item;
|
||||
gtk_list_insert_items( GTK_LIST (list), gitem_list, pos );
|
||||
|
||||
if (GTK_WIDGET_REALIZED(m_widget))
|
||||
{
|
||||
gtk_widget_realize( list_item );
|
||||
gtk_widget_realize( GTK_BIN(list_item)->child );
|
||||
|
||||
if (m_widgetStyle) ApplyWidgetStyle();
|
||||
}
|
||||
|
||||
gtk_widget_show( list_item );
|
||||
|
||||
EnableEvents();
|
||||
}
|
||||
|
||||
void wxComboBox::Insert( const wxString &item, int pos )
|
||||
{
|
||||
wxCHECK_RET(!(GetWindowStyle() & wxCB_SORT), wxT("can't insert into sorted list"));
|
||||
int count = GetCount();
|
||||
wxCHECK_RET((pos>=0) && (pos<=count), wxT("invalid index"));
|
||||
if (pos == count)
|
||||
{
|
||||
Append(item);
|
||||
return;
|
||||
}
|
||||
|
||||
m_clientDataList.Insert( pos, (wxObject*) NULL );
|
||||
m_clientObjectList.Insert( pos, (wxObject*) NULL );
|
||||
|
||||
InsertCommon( item, pos );
|
||||
}
|
||||
|
||||
void wxComboBox::Insert( const wxString &item, int pos, void *clientData )
|
||||
{
|
||||
wxCHECK_RET(!(GetWindowStyle() & wxCB_SORT), wxT("can't insert into sorted list"));
|
||||
int count = GetCount();
|
||||
wxCHECK_RET((pos>=0) && (pos<=count), wxT("invalid index"));
|
||||
if (pos == count)
|
||||
{
|
||||
Append(item, clientData);
|
||||
return;
|
||||
}
|
||||
|
||||
m_clientDataList.Insert( pos, (wxObject*) clientData );
|
||||
m_clientObjectList.Insert( pos, (wxObject*)NULL );
|
||||
|
||||
InsertCommon( item, pos );
|
||||
}
|
||||
|
||||
void wxComboBox::Insert( const wxString &item, int pos, wxClientData *clientData )
|
||||
{
|
||||
wxCHECK_RET(!(GetWindowStyle() & wxCB_SORT), wxT("can't insert into sorted list"));
|
||||
int count = GetCount();
|
||||
wxCHECK_RET((pos>=0) && (pos<=count), wxT("invalid index"));
|
||||
if (pos == count)
|
||||
{
|
||||
Append(item, clientData);
|
||||
return;
|
||||
}
|
||||
|
||||
m_clientDataList.Insert( pos, (wxObject*) NULL );
|
||||
m_clientObjectList.Insert( pos, (wxObject*) clientData );
|
||||
|
||||
InsertCommon( item, pos );
|
||||
}
|
||||
|
||||
void wxComboBox::SetClientData( int n, void* clientData )
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
|
||||
|
Reference in New Issue
Block a user