// g++ *.cc `pkg-config gtkmm-2.4 --cflags --libs`
#include <gtkmm.h>

// pointers to all the widgets
struct Widgets {
	Gtk::Window *pWin1;
	Gtk::ComboBoxEntry *pComboBoxEntry1;
	Glib::RefPtr<Gtk::ListStore> m_refTreeModel;

	// Tree model columns: but I don't want this in the code
	// I think glade can put it in the XML
	struct ModelColumns : Gtk::TreeModel::ColumnRecord {
		ModelColumns() {
			add(m_col_name);
		}
		Gtk::TreeModelColumn<Glib::ustring> m_col_name;
	} m_Columns;

	// constructor obtains pointers to the widgets made by builder
	Widgets(Glib::RefPtr<Gtk::Builder> builder) {
		builder->get_widget("window1", pWin1);
		builder->get_widget("comboboxentry1", pComboBoxEntry1);
		// I want to define this in the .glade file too
		m_refTreeModel = Gtk::ListStore::create(m_Columns);
		pComboBoxEntry1->set_model(m_refTreeModel);

		// It be nice to put initial rows in the glade file too
		// although I do want to add the ones that the user creates
		Gtk::TreeModel::Row row = *(m_refTreeModel->append());
		row[m_Columns.m_col_name] = "Option 1";

		row = *(m_refTreeModel->append());
		row[m_Columns.m_col_name] = "Option 2";

		row = *(m_refTreeModel->append());
		row[m_Columns.m_col_name] = "Option 3";

  		pComboBoxEntry1->set_text_column(m_Columns.m_col_name);
	}

	// exit when *pWin1 closes
	int run() {
		Gtk::Main::run(*pWin1);
		return EXIT_SUCCESS;
	}
};

int main(int argc, char *argv[]) {
	Gtk::Main kit(argc, argv);
	// instantiate the widgets as defined by glade's XML file
	Widgets allTheWidgets(
		Gtk::Builder::create_from_file("combo.glade")
	);
	// then run it's GUI application
	return allTheWidgets.run();
}

