Exemple #1
0
int main(int argc, char* argv[]) {
	Gtk::Main kit(argc, argv);
	Gtk::ComboBoxText combo;
	combo.append_text("asdfhbb");
	combo.append_text("45ggdfdfs");
	combo.append_text("avbbhrr");
	combo.append_text("khjgh2");
	combo.append_text("cxzeee");
	combo.append_text("quieroaprobartaller");
	BotonOrdenar boton(&combo);
	Gtk::VBox vbox;
	vbox.add(combo);
	vbox.add(boton);
	Gtk::Window v;
	v.add(vbox);
	v.show_all();
	Gtk::Main::run(v);
	return 0;
}	
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);
}
    inline virtual void updateGui()
    {
      _singleValueLabel.set_visible(false);
      for (size_t i(0); i < 4; ++i)
	_scalarvalues[i].hide();

      bool singlevalmode = singleValueMode();

      if (_components && singlevalmode)
	{
	  _singleValueLabel.set_visible(true);
	  for (size_t i(0); i < _components; ++i)
	    _scalarvalues[i].show();
	}

      _componentSelect.clear_items();
      if (singlevalmode || !_enableDataFiltering)
	_componentSelect.set_visible(false);
      else
	{
	  _componentSelect.set_visible(true);

	  Gtk::TreeModel::iterator iter = _comboBox.get_active();
	  std::tr1::shared_ptr<Attribute> ptr = (*iter)[_modelColumns.m_ptr];

	  _componentSelect.append_text("Raw Data");
	  _componentSelect.append_text("Magnitude");
	  _componentSelect.append_text("X");
	    
	  if (ptr->components() > 1)
	    _componentSelect.append_text("Y");
	  if (ptr->components() > 2)
	    _componentSelect.append_text("Z");
	  if (ptr->components() > 3)
	    _componentSelect.append_text("W");
	  
	  //Default to coloring using the magnitude
	  _componentSelect.set_active(1);
	}

      for (size_t i(0); i < _components; ++i)
	_scalarvalues[i].set_sensitive(singlevalmode);
    }
/*! 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 DimensionManager::addDimension() {
    Gtk::Dialog dialog(_("New Dimension"), true /*modal*/);
    // add dimension type combo box to the dialog
    Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(comboModel);
    for (int i = 0x01; i < 0xff; i++) {
        Glib::ustring sType =
            dimTypeAsString(static_cast<gig::dimension_t>(i));
        if (sType.find("Unknown") != 0) {
            Gtk::TreeModel::Row row = *(refComboModel->append());
            row[comboModel.m_type_id]   = i;
            row[comboModel.m_type_name] = sType;
        }
    }
    Gtk::Table table(2, 2);
    Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START);
    Gtk::ComboBox comboDimType;
    comboDimType.set_model(refComboModel);
    comboDimType.pack_start(comboModel.m_type_id);
    comboDimType.pack_start(comboModel.m_type_name);
    Gtk::Label labelZones(_("Zones:"), Gtk::ALIGN_START);
    table.attach(labelDimType, 0, 1, 0, 1);
    table.attach(comboDimType, 1, 2, 0, 1);
    table.attach(labelZones, 0, 1, 1, 2);
    dialog.get_vbox()->pack_start(table);

    // number of zones: use a combo box with fix values for gig
    // v2 and a spin button for v3
    Gtk::ComboBoxText comboZones;
    Gtk::SpinButton spinZones;
    bool version2 = false;
    if (region) {
        gig::File* file = (gig::File*)region->GetParent()->GetParent();
        version2 = file->pVersion && file->pVersion->major == 2;
    }
    if (version2) {
        for (int i = 1; i <= 5; i++) {
            char buf[3];
            sprintf(buf, "%d", 1 << i);
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 24) || GTKMM_MAJOR_VERSION < 2
            comboZones.append_text(buf);
#else
            comboZones.append(buf);
#endif
        }
        table.attach(comboZones, 1, 2, 1, 2);
    } else {
        spinZones.set_increments(1, 8);
        spinZones.set_numeric(true);
        spinZones.set_range(2, 128);
        spinZones.set_value(2);
        table.attach(spinZones, 1, 2, 1, 2);
    }

    dialog.add_button(_("_OK"), 0);
    dialog.add_button(_("_Cancel"), 1);
    dialog.show_all_children();

    if (!dialog.run()) { // OK selected ...
        Gtk::TreeModel::iterator iterType = comboDimType.get_active();
        if (!iterType) return;
        Gtk::TreeModel::Row rowType = *iterType;
        if (!rowType) return;
        int iTypeID = rowType[comboModel.m_type_id];
        gig::dimension_t type = static_cast<gig::dimension_t>(iTypeID);
        gig::dimension_def_t dim;
        dim.dimension = type;

        if (version2) {
            if (comboZones.get_active_row_number() < 0) return;
            dim.bits = comboZones.get_active_row_number() + 1;
            dim.zones = 1 << dim.bits;
        } else {
            dim.zones = spinZones.get_value_as_int();
            dim.bits = zoneCountToBits(dim.zones);
        }

        // assemble the list of regions where the selected dimension shall be
        // added to
        std::vector<gig::Region*> vRegions;
        if (allRegions()) {
            gig::Instrument* instr = (gig::Instrument*)region->GetParent();
            for (gig::Region* rgn = instr->GetFirstRegion(); rgn; rgn = instr->GetNextRegion()) {
                if (!rgn->GetDimensionDefinition(type)) vRegions.push_back(rgn);
            }
        } else vRegions.push_back(region);
            
        std::set<Glib::ustring> errors;

        for (uint iRgn = 0; iRgn < vRegions.size(); ++iRgn) {
            gig::Region* region = vRegions[iRgn];
            try {
                printf(
                    "Adding dimension (type=0x%x, bits=%d, zones=%d)\n",
                    dim.dimension, dim.bits, dim.zones
                );
                // notify everybody that we're going to update the region
                region_to_be_changed_signal.emit(region);
                // add the new dimension to the region
                // (implicitly creates new dimension regions)
                region->AddDimension(&dim);
                // let everybody know there was a change
                region_changed_signal.emit(region);
            } catch (RIFF::Exception e) {
                // notify that the changes are over (i.e. to avoid dead locks)
                region_changed_signal.emit(region);
                Glib::ustring txt = _("Could not add dimension: ") + e.Message;
                if (vRegions.size() == 1) {
                    // show error message directly
                    Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
                    msg.run();
                } else {
                    // remember error, they are shown after all regions have been processed
                    errors.insert(txt);
                }
            }
        }
        // update all GUI elements
        refreshManager();

        if (!errors.empty()) {
            Glib::ustring txt = _(
                "The following errors occurred while trying to create the dimension on all regions:"
            );
            txt += "\n\n";
            for (std::set<Glib::ustring>::const_iterator it = errors.begin();
                 it != errors.end(); ++it)
            {
                txt += "-> " + *it + "\n";
            }
            txt += "\n";
            txt += _(
                "You might also want to check the console for further warnings and "
                "error messages."
            );
            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
            msg.run();
        }
    }
}
Exemple #6
0
/**
    \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);
}
Exemple #7
0
    Argument::Argument (const MR::Argument& argument) :
      arg (argument),
      description_label (arg.lname)
    {
      set_border_width (GUI_SPACING);
      set_spacing (GUI_SPACING);
      pack_start (description_label, Gtk::PACK_SHRINK);

      switch (arg.type) {
        case Integer: 
          {
            Gtk::SpinButton* sb = manage (new Gtk::SpinButton);
            sb->set_value (arg.extra_info.i.def);
            sb->set_range (arg.extra_info.i.min, arg.extra_info.i.max);
            sb->set_increments (1, 10);
            pack_start (*sb);
            widget = (void*) sb;
          }
          break;
        case Float:
          {
            Gtk::SpinButton* sb = manage (new Gtk::SpinButton);
            sb->set_range (arg.extra_info.f.min, arg.extra_info.f.max);
            sb->set_increments (
                1e-4 *(arg.extra_info.f.max-arg.extra_info.f.min), 
                1e-2 *(arg.extra_info.f.max-arg.extra_info.f.min));
            sb->set_digits (4);
            sb->set_value (arg.extra_info.f.def);
            pack_start (*sb);
            widget = (void*) sb;
          }
          break;
        case Text:
        case IntSeq:
        case FloatSeq: 
          { 
            Gtk::Entry* entry = manage (new Gtk::Entry);
            pack_start (*entry);
            widget = (void*) entry;
          }
          break;
        case ArgFile:
        case ImageIn:
        case ImageOut:
          { 
            Gtk::Entry* entry = manage (new Gtk::Entry);
            Gtk::Button* browse = manage (new Gtk::Button (Gtk::Stock::OPEN));
            browse->signal_clicked().connect (sigc::mem_fun (*this, &Argument::on_browse));
            pack_start (*entry);
            pack_start (*browse, Gtk::PACK_SHRINK);
            widget = (void*) entry;
          }
          break;
        case Choice:
          {
            Gtk::ComboBoxText* choice = manage (new Gtk::ComboBoxText);
            for (const gchar** p = arg.extra_info.choice; *p; p++) choice->append_text (*p);
            choice->set_active (0);
            pack_start (*choice);
            widget = (void*) choice;
          }
          break;
        default: break;
      }

      set_tooltip_text (arg.desc);
    }