// Bug 619656 - CellRendererText property changes are not reflected in ComboBoxText

// Modified version of the test case in comment 2.
// Modifications are marked with double exclamation marks (!!).

#include <set>
#include <vector> //!! Added
#include <gtkmm.h>
#include <iostream>

using namespace std;

typedef std::set<Glib::ustring> FontSet;

class FontSelector : public Gtk::ComboBoxText {
public:
    FontSelector() {
         // add colummns to model
        col_records.add(col1);
        refStore = Gtk::ListStore::create(col_records);
        set_model(refStore);

        // add the font family names to the combobox
        Glib::RefPtr<Pango::Context> pc = this->get_pango_context();
        if(pc) {
            FontSet fonts;
            Glib::ArrayHandle<Glib::RefPtr<Pango::FontFamily> > families =
               pc->list_families();
            for(Glib::ArrayHandle<Glib::RefPtr<Pango::FontFamily> >::iterator
                it = families.begin(); it < families.end(); it++) {
                fonts.insert((*it)->get_name());
            }
            for(FontSet::iterator it = fonts.begin(); it != fonts.end(); it++)
            {
                addrow(*it);
            }
        }

        // show font family text in the font family
//!! Added
        std::vector<Gtk::CellRenderer*> cell_renderers = get_cells();
        // Assume that there is exactly one cell renderer now.
        if (cell_renderers.size() == 1)
        {
           Gtk::CellRendererText* cell_renderer_text =
              dynamic_cast<Gtk::CellRendererText*>(cell_renderers[0]);
           if (cell_renderer_text)
           {
              add_attribute(*cell_renderer_text, "family", 0);
           }
           else
           {
              std::cout << "Wrong type of cell renderer!" << std::endl;
           }
        }
        else
        {
           std::cout << cell_renderers.size() << " cell renderers!" << std::endl;
        }
//!! End of added
        pack_start(renderer, true);
//!! Removed        add_attribute(renderer, "family", 0);
        sigc::slot<void, const Gtk::TreeIter> s = sigc::mem_fun(*this,
           &FontSelector::set_family);
        set_cell_data_func(renderer, s);
    }

private:
    Gtk::TreeModelColumnRecord col_records;
    Glib::RefPtr<Gtk::ListStore> refStore;
    Gtk::TreeModelColumn<Glib::ustring> col1;
    Gtk::CellRendererText renderer;

    // add the font family into the combobox
    void addrow(Glib::ustring family) {
        Gtk::ListStore::iterator it = refStore->append();
        Gtk::ListStore::Row row = *it;
        row[col1] = family;
    }

    // set font properties for display of combobox items
    void set_family(const Gtk::TreeIter iter) {
        Gtk::TreeModel::Row row = *iter;
        Glib::ustring family = row[col1];
        renderer.property_family() = family;
        renderer.property_style() = Pango::STYLE_ITALIC;
        renderer.property_size_points() = 20;
        renderer.property_text() = family; //!! Added
    } 
};

int main(int argc, char** argv) {
    Gtk::Main kit(argc, argv);
    Gtk::Window window;
    FontSelector fs;
    window.add(fs);
    fs.show();
    Gtk::Main::run(window);
}

