//------------------------------------------------------------------------------
void mforms::gtk::ToolBarImpl::set_item_text(mforms::ToolBarItem *item, const std::string &label) {
  const mforms::ToolBarItemType type = item->get_type();

  switch (type) {
    case mforms::TextActionItem:
    case mforms::ActionItem:
    case mforms::SegmentedToggleItem:
    case mforms::ToggleItem:
    case mforms::SwitcherItem: {
      Gtk::Button *btn = cast<Gtk::Button *>(item->get_data_ptr());
      if (type == mforms::SwitcherItem) {
        btn->set_label(label);
        btn->get_style_context()->add_class("SwitcherItem");
      } else
        btn->add_label(label);
      btn->set_name(label);
      break;
    }
    case mforms::TitleItem:
    case mforms::LabelItem: {
      Gtk::Label *lbl = cast<Gtk::Label *>(item->get_data_ptr());
      if (lbl) {
        lbl->set_markup("<small>" + label + "</small>");
        lbl->set_name(label);
      }
      break;
    }
    case mforms::FlatSelectorItem:
    case mforms::SelectorItem: {
      Gtk::ComboBoxText *ct = cast<Gtk::ComboBoxText *>(item->get_data_ptr());
      if (ct)
        ct->set_active_text(label);
      break;
    }
    case mforms::ColorSelectorItem: {
      Gtk::ComboBox *combo = cast<Gtk::ComboBox *>(item->get_data_ptr());
      if (combo) {
        Glib::RefPtr<Gtk::TreeModel> model = combo->get_model();
        if (model) {
          const Gtk::TreeModel::Children children = model->children();
          const Gtk::TreeIter last = children.end();
          Gtk::TreeRow row;

          for (Gtk::TreeIter it = children.begin(); it != last; ++it) {
            row = *it;
            if (row.get_value(color_combo_columns->color) == label) {
              combo->set_active(it);
              break;
            }
          }
        }
      }
      break;
    }
    case mforms::SearchFieldItem:
    case mforms::TextEntryItem: {
      Gtk::Entry *e = cast<Gtk::Entry *>(item->get_data_ptr());
      if (e)
        e->set_text(label);
      break;
    }
    case mforms::SeparatorItem:
    case mforms::ExpanderItem:
    case mforms::ImageBoxItem:
      break;
  }
}