void PrefPage::appendCombo(const std::string& name, const std::string& registryKey, const ComboBoxValueList& valueList, bool storeValueNotIndex) { Gtk::Alignment* alignment = Gtk::manage(new Gtk::Alignment(0.0, 0.5, 0.0, 0.0)); // Create a new combo box of the correct type using boost::shared_ptr; using namespace gtkutil; Gtk::ComboBoxText* combo = Gtk::manage(new Gtk::ComboBoxText); // Add all the string values to the combo box for (ComboBoxValueList::const_iterator i = valueList.begin(); i != valueList.end(); ++i) { combo->append_text(*i); } if (storeValueNotIndex) { // There is no property_active_text() apparently, so we have to connect // manually combo->set_active_text(_registryBuffer.get(registryKey)); combo->property_active().signal_changed().connect( sigc::bind( sigc::ptr_fun(setRegBufferValueFromActiveText), combo, registryKey, sigc::ref(_registryBuffer) ) ); _resetValuesSignal.connect( sigc::bind(sigc::ptr_fun(setActiveTextFromRegValue), combo, registryKey) ); } else { registry::bindPropertyToBufferedKey(combo->property_active(), registryKey, _registryBuffer, _resetValuesSignal); } // Add it to the container alignment->add(*combo); // Add the widget to the dialog row appendNamedWidget(name, *alignment); }
//------------------------------------------------------------------------------ void mforms::gtk::ToolBarImpl::set_selector_items(ToolBarItem *item, const std::vector<std::string> &values) { if (item->get_type() == mforms::SelectorItem || item->get_type() == mforms::FlatSelectorItem) { Gtk::ComboBoxText *w = cast<Gtk::ComboBoxText *>(item->get_data_ptr()); if (w) { w->set_data("ignore_signal", (void *)1); #if ((GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 24) || GTKMM_MAJOR_VERSION > 2) w->remove_all(); #else w->clear_items(); #endif const int size = values.size(); for (int i = 0; i < size; ++i) w->append(values[i]); if (w->get_active_row_number() < 0 && !values.empty()) w->set_active_text(values[0]); w->set_data("ignore_signal", 0); } } else if (item->get_type() == mforms::ColorSelectorItem) { Gtk::ComboBox *w = cast<Gtk::ComboBox *>(item->get_data_ptr()); if (w) { w->set_data("ignore_signal", (void *)1); Glib::RefPtr<Gtk::ListStore> model = Gtk::ListStore::create(*color_combo_columns); const int size = values.size(); for (int i = 0; i < size; ++i) { Gtk::TreeRow row = *model->append(); Gdk::Color color(values[i]); Glib::RefPtr<Gdk::Pixbuf> pixbuf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, false, 8, 16, 14); pixbuf->fill((guint32)color.get_red() << 24 | (guint32)color.get_green() << 16 | (guint32)color.get_blue() << 8); row[color_combo_columns->color] = values[i]; row[color_combo_columns->image] = pixbuf; } w->set_model(model); if (w->get_active_row_number() < 0) w->set_active(0); w->set_data("ignore_signal", 0); } } }
/*! Constructor * \param[in] el the configuration element to display * \param[in] differ shall the changes be applied later using apply_changes()? */ ConfigElement::ConfigElement(crn::ConfigElement &el, bool differ): value(el.GetValue()), tmpvalue(el.GetValue()) { if (!value) throw crn::ExceptionUninitialized(_("The element was not initialized.")); if (differ) tmpvalue = crn::Clone(*value); if (std::dynamic_pointer_cast<crn::Int>(tmpvalue)) typ = U"Int"; else if (std::dynamic_pointer_cast<crn::Real>(tmpvalue)) typ = U"Real"; else if (std::dynamic_pointer_cast<crn::Prop3>(tmpvalue)) typ = U"Prop3"; else if (std::dynamic_pointer_cast<crn::String>(tmpvalue)) typ = U"String"; else if (std::dynamic_pointer_cast<crn::StringUTF8>(tmpvalue)) typ = U"StringUTF8"; else if (std::dynamic_pointer_cast<crn::Path>(tmpvalue)) typ = U"Path"; Gtk::Label *lab = Gtk::manage(new Gtk::Label(el.GetName().CStr())); lab->show(); pack_start(*lab, false, true, 2); if (typ == U"Prop3") { Prop3 *p = Gtk::manage(new Prop3(Gtk::ICON_SIZE_BUTTON, el.GetValue<crn::Prop3>())); p->signal_value_changed().connect(sigc::mem_fun(this, &ConfigElement::on_p3_changed)); p->show(); pack_start(*p, true, true, 2); } else if (!el.GetAllowedValues().IsEmpty()) { // any Int, Real, String, StringUTF8 or Path Gtk::ComboBoxText *cb = Gtk::manage(new Gtk::ComboBoxText); const std::vector<crn::StringUTF8> values(el.GetAllowedValues<crn::StringUTF8>()); for (const crn::StringUTF8 &val : values) #ifdef CRN_USING_GTKMM3 cb->append(val.CStr()); #else /* CRN_USING_GTKMM3 */ cb->append_text(val.CStr()); #endif /* CRN_USING_GTKMM3 */ cb->set_active_text(el.GetValue<crn::StringUTF8>().CStr()); cb->signal_changed().connect(sigc::bind(sigc::mem_fun(this, &ConfigElement::on_combo_changed), cb)); cb->show(); pack_start(*cb, true, true, 2); } else if (typ == U"Int") { if (el.HasMinValue() && el.HasMaxValue()) { // has finite range, use a slider #ifdef CRN_USING_GTKMM3 auto *s = Gtk::manage(new Gtk::Scale(Gtk::ORIENTATION_HORIZONTAL)); s->set_range(el.GetMinValue<int>(), el.GetMaxValue<int>() + 1); s->set_increments(1, 1); #else Gtk::HScale *s = Gtk::manage(new Gtk::HScale(el.GetMinValue<int>(), el.GetMaxValue<int>() + 1, 1)); #endif s->set_value(el.GetValue<int>()); s->signal_value_changed().connect(sigc::bind(sigc::mem_fun(this, &ConfigElement::on_range_changed), s)); s->show(); pack_start(*s, true, true, 2); } else { // has at least one infinite (maxed) bound, use a spin button Gtk::SpinButton *s = Gtk::manage(new Gtk::SpinButton); int m = std::numeric_limits<int>::min(), M = std::numeric_limits<int>::max(); if (el.HasMinValue()) m = el.GetMinValue<int>(); if (el.HasMaxValue()) M = el.GetMaxValue<int>(); s->set_range(m, M); s->set_increments(1, 10); s->set_value(el.GetValue<int>()); s->signal_value_changed().connect(sigc::bind(sigc::mem_fun(this, &ConfigElement::on_spin_changed), s)); s->show(); pack_start(*s, true, true, 2); } } else if (typ == U"Real") { if (el.HasMinValue() && el.HasMaxValue()) { // has finite range, use a slider #ifdef CRN_USING_GTKMM3 auto *s = Gtk::manage(new Gtk::Scale(Gtk::ORIENTATION_HORIZONTAL)); s->set_range(el.GetMinValue<double>(), el.GetMaxValue<double>() + 0.01); s->set_increments(0.01, 0.01); #else Gtk::HScale *s = Gtk::manage(new Gtk::HScale(el.GetMinValue<double>(), el.GetMaxValue<double>() + 0.01, 0.01)); #endif s->set_digits(2); s->set_value(el.GetValue<double>()); s->signal_value_changed().connect(sigc::bind(sigc::mem_fun(this, &ConfigElement::on_range_changed), s)); s->show(); pack_start(*s, true, true, 2); } else { // has at least one infinite (maxed) bound, use a spin button Gtk::SpinButton *s = Gtk::manage(new Gtk::SpinButton(0, 2)); double m = -std::numeric_limits<double>::max(), M = std::numeric_limits<double>::max(); if (el.HasMinValue()) m = el.GetMinValue<double>(); if (el.HasMaxValue()) M = el.GetMaxValue<double>(); s->set_range(m, M); s->set_increments(0.01, 1); s->set_value(el.GetValue<double>()); s->signal_value_changed().connect(sigc::bind(sigc::mem_fun(this, &ConfigElement::on_spin_changed), s)); s->show(); pack_start(*s, true, true, 2); } } else // string types { Gtk::Entry *e = Gtk::manage(new Gtk::Entry); e->set_text(el.GetValue<crn::StringUTF8>().CStr()); e->signal_changed().connect(sigc::bind(sigc::mem_fun(this, &ConfigElement::on_entry_changed), e)); e->show(); pack_start(*e, true, true, 2); } lab = Gtk::manage(new Gtk::Label("?")); lab->show(); lab->set_tooltip_text(el.GetDescription().CStr()); pack_start(*lab, false, true, 2); }
//------------------------------------------------------------------------------ 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; } }
/** \brief Creates a combobox widget for an enumeration parameter */ Gtk::Widget * ParamRadioButton::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { if (_gui_hidden) return NULL; Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox(false, 0)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT, Gtk::ALIGN_TOP)); label->show(); hbox->pack_start(*label, false, false); Gtk::ComboBoxText* cbt = 0; bool comboSet = false; if (_mode == MINIMAL) { cbt = Gtk::manage(new ComboWdg(this, doc, node)); cbt->show(); vbox->pack_start(*cbt, false, false); } // add choice strings as radiobuttons // and select last selected option (_value) Gtk::RadioButtonGroup group; for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { optionentry * entr = reinterpret_cast<optionentry *>(list->data); Glib::ustring * text = entr->guitext; switch ( _mode ) { case MINIMAL: { cbt->append_text(*text); if (!entr->value->compare(_value)) { cbt->set_active_text(*text); comboSet = true; } } break; case COMPACT: case FULL: { ParamRadioButtonWdg * radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node, changeSignal)); radio->show(); vbox->pack_start(*radio, true, true); if (!entr->value->compare(_value)) { radio->set_active(); } } break; } } if ( (_mode == MINIMAL) && !comboSet) { cbt->set_active(0); } vbox->show(); hbox->pack_end(*vbox, false, false); hbox->show(); return dynamic_cast<Gtk::Widget *>(hbox); }