Ejemplo n.º 1
0
int wxListBox::DoAppend( const wxString& item )
{
    InvalidateBestSize();

    if (m_strings)
    {
        // need to determine the index
        int index = m_strings->Add( item );

        // only if not at the end anyway
        if (index != (int)GetCount())
        {
           GtkAddItem( item, index );

           wxList::compatibility_iterator node = m_clientList.Item( index );
           m_clientList.Insert( node, (wxObject *)NULL );

           return index;
        }
    }

    GtkAddItem(item);

    m_clientList.Append((wxObject *)NULL);

    return GetCount() - 1;
}
Ejemplo n.º 2
0
int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items,
                             unsigned int pos,
                             void **clientData,
                             wxClientDataType type)
{
    wxCHECK_MSG( m_list != NULL, wxNOT_FOUND, wxT("invalid listbox") );

    const unsigned count = GetCount();
    wxCHECK_MSG( pos <= count, wxNOT_FOUND,
                    wxT("invalid index in wxListBox::InsertItems") );

    // code elsewhere supposes we have as many items in m_clientList as items
    // in the listbox
    wxASSERT_MSG( m_clientList.GetCount() == count,
                      wxT("bug in client data management") );

    InvalidateBestSize();

    const unsigned numItems = items.GetCount();

    for ( unsigned int n = 0; n < numItems; ++n, ++pos )
    {
        const wxString& item = items[n];

        const unsigned idx = m_strings ? m_strings->Add(item)
                                       : pos;

        GtkAddItem(item, idx == GetCount() ? (unsigned) -1 : idx);

        m_clientList.Insert(idx, NULL);

        AssignNewItemClientData(idx, clientData, n, type);
    }

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

    return pos - 1;
}
Ejemplo n.º 3
0
void wxListBox::DoInsertItems(const wxArrayString& items, unsigned int pos)
{
    wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );

    // VZ: notice that InsertItems knows nothing about sorting, so calling it
    //     from outside (and not from our own Append) is likely to break
    //     everything

    // code elsewhere supposes we have as many items in m_clientList as items
    // in the listbox
    wxASSERT_MSG( m_clientList.GetCount() == GetCount(),
                  wxT("bug in client data management") );

    InvalidateBestSize();

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

    wxCHECK_RET( pos <= length, wxT("invalid index in wxListBox::InsertItems") );

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

    if (m_strings)
    {
        for (unsigned int n = 0; n < nItems; n++)
        {
            index = m_strings->Add( items[n] );

            if (index != (int)GetCount())
            {
                GtkAddItem( items[n], index );
                wxList::compatibility_iterator node = m_clientList.Item( index );
                m_clientList.Insert( node, (wxObject*) NULL );
            }
            else
            {
                GtkAddItem( items[n] );
                m_clientList.Append( (wxObject*) NULL );
            }
        }
    }
    else
    {
        if (pos == length)
        {
            for ( unsigned int n = 0; n < nItems; n++ )
            {
                GtkAddItem( items[n] );

                m_clientList.Append((wxObject *)NULL);
            }
        }
        else
        {
            wxList::compatibility_iterator node = m_clientList.Item( pos );
            for ( unsigned int n = 0; n < nItems; n++ )
            {
                GtkAddItem( items[n], pos+n );

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

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