inline bool singleValueMode() { Gtk::TreeModel::iterator iter = _comboBox.get_active(); if (!iter) return true; std::tr1::shared_ptr<Attribute> ptr = (*iter)[_modelColumns.m_ptr]; return !ptr; }
void eraseComboboxActive(string n) { Gtk::ComboBox* cb; VRGuiBuilder()->get_widget(n, cb); //Glib::RefPtr<Gtk::TreeModel> model = cb->get_model() GtkTreeModel* model = cb->get_model()->gobj(); //model->erase(cb->get_active()); gtk_list_store_remove(GTK_LIST_STORE(model), cb->get_active().gobj()); cb->set_active(cb->get_model()->children().size() - 1); }
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); }
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(); } } }
void DimensionManager::onColumnClicked() { printf("DimensionManager::onColumnClicked()\n"); //FIXME: BUG: this method is currently very unreliably called, it should actually be called when the user selects another column, it is ATM however also called when the table content changed programmatically causing the dialog below to popup at undesired times ! //HACK: Prevents that onColumnClicked() gets called multiple times or at times where it is not desired if (ignoreColumnClicked) { ignoreColumnClicked = false; return; } #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 18) || GTKMM_MAJOR_VERSION > 2 // prevents app to crash if this dialog is closed if (!get_visible()) return; #else # warning Your GTKMM version is too old; dimension manager dialog might crash when changing a dimension type ! #endif #if (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 3 if (!is_visible()) return; #endif Gtk::TreeModel::Path path; Gtk::TreeViewColumn* focus_column; treeView.get_cursor(path, focus_column); //const int row = path[0]; if (focus_column == treeView.get_column(0)) { Gtk::TreeModel::iterator it = treeView.get_model()->get_iter(path); if (!it) return; Gtk::TreeModel::Row row = *it; gig::dimension_t oldType = row[tableModel.m_type]; Gtk::Dialog dialog(_("Change Dimension"), true /*modal*/); int oldTypeIndex = -1; Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(comboModel); for (int i = 0x01, count = 0; i < 0xff; i++) { Glib::ustring sType = dimTypeAsString(static_cast<gig::dimension_t>(i)); if (i == oldType) oldTypeIndex = count; if (sType.find("Unknown") != 0) { Gtk::TreeModel::Row row = *(refComboModel->append()); row[comboModel.m_type_id] = i; row[comboModel.m_type_name] = sType; count++; } } Gtk::Table table(1, 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); table.attach(labelDimType, 0, 1, 0, 1); table.attach(comboDimType, 1, 2, 0, 1); dialog.get_vbox()->pack_start(table); dialog.add_button(_("_OK"), 0); dialog.add_button(_("_Cancel"), 1); dialog.show_all_children(); comboDimType.set_active(oldTypeIndex); if (!dialog.run()) { // OK selected ... ignoreColumnClicked = true; 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 newType = static_cast<gig::dimension_t>(iTypeID); if (newType == oldType) return; //printf("change 0x%x -> 0x%x\n", oldType, newType); // assemble the list of regions where the selected dimension type // shall be changed 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(oldType)) 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 { // notify everybody that we're going to update the region region_to_be_changed_signal.emit(region); // change the dimension type on that region region->SetDimensionType(oldType, newType); // 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 alter 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 change the dimension type 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(); } } } }
void on_combobox_changed() { ::Gtk::TreeModel::iterator iter = _comboBox.get_active(); if (iter) _mode = ((*iter)[m_Columns.m_col_id]); _signal_changed.emit(); }
Gtk::TreeModel::iterator getComboboxIter(string cbn) { Gtk::ComboBox* cb; VRGuiBuilder()->get_widget(cbn.c_str(), cb); return cb->get_active(); }
Gtk::TreeModel::Row getComboboxRow(string cbn) { Gtk::ComboBox* cb; VRGuiBuilder()->get_widget(cbn.c_str(), cb); return *cb->get_active(); }