コード例 #1
0
const StringColumn& ColumnsModel::append_string_column(const int bec_tm_idx, const std::string& name,
                                                       const Editable editable, const Iconic have_icon) {
  Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>>* icon = 0;

  Gtk::TreeViewColumn* column = Gtk::manage(new Gtk::TreeViewColumn(base::replaceString(name, "_", "__")));

  if (have_icon == WITH_ICON) {
    icon = new Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>>;
    add(*icon);
    add_bec_index_mapping(bec_tm_idx);
    column->pack_start(*icon, false);

    _columns.push_back(icon);
  }

  Gtk::TreeModelColumn<Glib::ustring>* col = new Gtk::TreeModelColumn<Glib::ustring>;
  add(*col);
  add_bec_index_mapping(bec_tm_idx);
  column->pack_start(*col);

  _columns.push_back(col);

  int nr_of_cols = _treeview->append_column(*column);
  _treeview->get_column(nr_of_cols - 1)->set_resizable(true);

  if (editable == EDITABLE || editable == EDITABLE_WO_FIRST) {
    std::vector<Gtk::CellRenderer*> rends = column->get_cells();

    Gtk::CellRendererText* cell = (Gtk::CellRendererText*)rends[icon ? 1 : 0];
    cell->property_editable() = true;
    cell->signal_edited().connect(
      sigc::bind(sigc::mem_fun(*_tmw, &ListModelWrapper::after_cell_edit<Glib::ustring>), sigc::ref(*col)));

    if (editable == EDITABLE_WO_FIRST)
      column->set_cell_data_func(*cell, sigc::mem_fun(this, &ColumnsModel::disable_edit_first_row));
  }

  return *col;
}