wxWidgets / wxWidgets

Cross-Platform C++ GUI Library
https://www.wxwidgets.org/
6.34k stars 1.79k forks source link

wxListBox:Set don't work, when style wxLB_SORT is used. #19454

Closed wxtrac closed 3 years ago

wxtrac commented 24 years ago

Issue migrated from trac ticket # 89

component: wxGTK | priority: normal

2000-11-28 09:56:59: rscholz created the issue


When using the style wxLB_SORT with wxListBox in wxGTK, the Set method don't work. This is bad, because the Set method works with the Windows version and it's better to use the Set method instead of Clear and Append to reduce flicker. Using the following DoInsertItems method in listbox.cpp cures the problem (it has be be integrated in the official version):

void wxListBox::DoInsertItems(const wxArrayString& items, int pos) { wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );

// code elsewhere supposes we have as many items in m_clientList as

items // in the listbox wxASSERT_MSG( m_clientList.GetCount() == (size_t)GetCount(), wxT("bug in client data management") );

GList *children = m_list->children;
int length = g_list_length(children);

wxCHECK_RET( pos <= length, wxT("invalid index in

wxListBox::InsertItems") );

size_t nItems = items.GetCount();
int index;

if (m_strings)
{
    for ( size_t n = 0; n < nItems; n++ )
    {

       // need to determine the index
       index = m_strings->Add( items[n] );

       // only if not at the end anyway
       if (index != GetCount())
       {
          GtkAddItem( items[n], index );

          wxNode *node = m_clientList.Nth( index );
          m_clientList.Insert( node, (wxObject *)NULL );
       } else
       {
          GtkAddItem( items[n] );

          m_clientList.Append((wxObject *)NULL);
       }
    }
} else
{
   if (pos == length)
   {
      for ( size_t n = 0; n < nItems; n++ )
      {
          GtkAddItem( items[n] );

          m_clientList.Append((wxObject *)NULL);
      }
   }
   else
   {
      wxNode *node = m_clientList.Nth( pos );
      for ( size_t n = 0; n < nItems; n++ )
      {
          GtkAddItem( items[n], pos+n );

          m_clientList.Insert( node, (wxObject *)NULL );
      }
   }
}

wxASSERT_MSG( m_clientList.GetCount() == (size_t)GetCount(),
                  wxT("bug in client data management") );

}

wxtrac commented 24 years ago

2000-12-16 13:11:02: roebling (Robert Roebling) commented


Applied patch.