Hi,

I'm using gtkmm 2.12.7 (as in Debian Sid).

I have testing program which contains only of 2 Gtk::Entries. In one
user should enter somebody's name and in a second - somebody's surname.
I wanted it to work that way, when user selects a name in name entry,
its corresponding surname should appear in surname entry.

Example:
User has entered "A" in name entry, so four names appear - Arturo,
Andrzej, Anthony and Aleksander. User selects Anthony and this name
appears in name entry and in the same time in surname entry "Burgess"
word appears.

I set EntryCompletion for each entry and a list of names/surnames
appears while entering data to entry. So it works. Each EntryCompletion
uses the same TreeModel, but with different text columns. But when I
want to connect my custom function to EntryCompletion's
signal_match_selected (or to any other its signals), program still uses
a default behavior. I was just following instructions in documentation.
Making a class inheriting from Gtk::EntryCompletion and overriding a
on_match_selected (like in Gtk::Util::MultiEntryCompletion) does not
work for me, because in overriden function I need access to both entries
to set their texts.

Am I doing something wrong? I'd appreciate any help.

Here is my code (cut for brevity):
BEGIN CODE BLOCK
#include <iostream>

#include "complwindow.h"

ComplWindow::ComplWindow(BaseObjectType* cobject,
                         Glib::RefPtr<Gnome::Glade::Xml> xml) :
Gtk::Window(cobject),
m_ref_glade(xml),
m_name_entry(dynamic_cast<Gtk::Entry*>(m_ref_glade->get_widget("name_entry"))),
m_surname_entry(dynamic_cast<Gtk::Entry*>(m_ref_glade->get_widget("surname_entry"))),
m_ref_name_compl(Gtk::EntryCompletion::create()),
m_ref_surname_compl(Gtk::EntryCompletion::create()),
m_model_columns(),
m_ref_tree_model(Gtk::ListStore::create(m_model_columns))
{
        Gtk::TreeModel::Row data_row = *(m_ref_tree_model->append());
        data_row[m_model_columns.m_id] = 1;
        data_row[m_model_columns.m_name] = Glib::ustring("Bram");
        data_row[m_model_columns.m_surname] = Glib::ustring("Stoker");
        data_row = *(m_ref_tree_model->append());
        data_row[m_model_columns.m_id] = 2;
        data_row[m_model_columns.m_name] = Glib::ustring("Robert");
        data_row[m_model_columns.m_surname] = Glib::ustring("Jordan");
        // and so on.
        m_ref_name_compl->set_model(m_ref_tree_model);
        m_ref_surname_compl->set_model(m_ref_tree_model);
        m_ref_name_compl->set_text_column(m_model_columns.m_name);
        m_ref_surname_compl->set_text_column(m_model_columns.m_surname);
        m_name_entry->set_completion(m_ref_name_compl);
        m_surname_entry->set_completion(m_ref_surname_compl);
        m_ref_name_compl->signal_match_selected().connect(sigc::mem_fun(*this,
&ComplWindow::on_match_selected));
}

bool
ComplWindow::on_match_selected(const Gtk::TreeModel::iterator& iter)
{
        Glib::ustring name((*iter)[m_model_columns.m_name]);
        Glib::ustring surname((*iter)[m_model_columns.m_surname]);
        std::cout << name << " " << surname << std::endl;
        m_name_entry->set_text(name);
        m_surname_entry->set_text(surname);
        return true;
}
END CODE BLOCK

I attached an archive with whole source code (glade file included).

Thanks,
Krzesimir

Attachment: completion_entry.tar.gz
Description: application/compressed-tar

_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to