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();
        }
    }
}
//------------------------------------------------------------------------------
bool mforms::gtk::ToolBarImpl::create_tool_item(mforms::ToolBarItem *item, ToolBarItemType type) {
  Gtk::Widget *w = 0;
  switch (type) {
    case mforms::TextActionItem:
    case mforms::ActionItem:
    case mforms::SwitcherItem: {
      Gtk::Button *btn = Gtk::manage(new Gtk::Button());
      btn->set_focus_on_click(false);
      btn->set_border_width(0);
      btn->set_relief(Gtk::RELIEF_NONE);
      btn->signal_clicked().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), btn, item));
      if (type == mforms::SwitcherItem)
        btn->set_always_show_image(true);
      w = btn;
      break;
    }
    case mforms::SegmentedToggleItem:
    case mforms::ToggleItem: {
      Gtk::ToggleButton *btn = Gtk::manage(new Gtk::ToggleButton());
      btn->set_focus_on_click(false);
      btn->set_relief(Gtk::RELIEF_NONE);
      btn->signal_toggled().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), btn, item));
      btn->set_inconsistent(false);

      w = btn;
      break;
    }
    case mforms::SeparatorItem: {
      Gtk::Separator *sep = new Gtk::Separator(Gtk::ORIENTATION_VERTICAL);
      w = sep;
      break;
    }
    case mforms::SearchFieldItem: {
#if GTK_VERSION_GE(2, 16)
      Gtk::Entry *entry = Gtk::manage(new Gtk::Entry());
      w = entry;
      entry->set_icon_from_stock(Gtk::Stock::FIND);
#else
      Gtk::Box *hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0));
      w = hbox;
      Gtk::Image *image = Gtk::manage(new Gtk::Image(Gtk::Stock::FIND, Gtk::ICON_SIZE_MENU));
      Gtk::Entry *entry = Gtk::manage(new Gtk::Entry());

      hbox->pack_start(*image, false, true);
      hbox->pack_start(*entry, true, true);
      hbox->set_data("entry", entry);
      hbox->show_all();
#endif
      entry->signal_activate().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), entry, item));
      break;
    }
    case mforms::TextEntryItem: {
      Gtk::Box *hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0));
      w = hbox;
      Gtk::Entry *entry = Gtk::manage(new Gtk::Entry());
      hbox->pack_start(*entry, true, true);
      hbox->set_data("entry", entry);
      hbox->show_all();
      entry->signal_activate().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), entry, item));
      break;
    }
    case mforms::FlatSelectorItem:
    case mforms::SelectorItem: {
      Gtk::ComboBoxText *ct = Gtk::manage(new Gtk::ComboBoxText());
      ct->signal_changed().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), ct, item));

      w = ct;
      break;
    }
    case mforms::ColorSelectorItem: {
      if (!color_combo_columns) {
        color_combo_columns = new ColorComboColumns();
      }
      Gtk::ComboBox *ct = Gtk::manage(new Gtk::ComboBox());

      ct->pack_start(color_combo_columns->image);
      ct->signal_changed().connect(sigc::bind(sigc::ptr_fun(process_ctrl_action), ct, item));

      w = ct;

      break;
    }
    case mforms::ExpanderItem:
    case mforms::LabelItem: {
      Gtk::Label *label = Gtk::manage(new Gtk::Label("", 0.0, 0.5));
      w = label;
      break;
    }
    case mforms::ImageBoxItem: {
      Gtk::Image *image = Gtk::manage(new Gtk::Image());
      w = image;
      break;
    }
    case mforms::TitleItem: {
      Gtk::Label *label = Gtk::manage(new Gtk::Label("", 0.0, 0.5));
      w = label;
      auto provider = Gtk::CssProvider::create();
      provider->load_from_data("* { color: #333; font-weight: bold; }");
      w->get_style_context()->add_provider(provider, GTK_STYLE_PROVIDER_PRIORITY_USER);
      break;
    }
  }

  if (w) {
    w->show();
  } else
    logError("create_tool_item, widget is 0 for passed type %i\n", type);

  item->set_data(w);

  return w != 0;
}
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();
            }
        }
    }
}
示例#4
0
void Settings::connect_to_ui (Builder &builder)
{
  // connect gcode configurable text sections
  GCode.m_impl->connectToUI (builder);

  // first setup ranges on spinbuttons ...
  for (uint i = 0; i < G_N_ELEMENTS (spin_ranges); i++) {
    Gtk::SpinButton *spin = NULL;
    builder->get_widget (spin_ranges[i].widget, spin);
    if (!spin)
      std::cerr << "missing spin button of name '" << spin_ranges[i].widget << "'\n";
    else {
      spin->set_range (spin_ranges[i].min, spin_ranges[i].max);
      spin->set_increments (spin_ranges[i].inc, spin_ranges[i].inc_page);
    }
  }
  // Ranges on [HV]Range widgets
  for (uint i = 0; i < G_N_ELEMENTS (ranges); i++) {
    Gtk::Range *range = NULL;
    builder->get_widget (ranges[i].widget, range);
    if (!range)
      std::cerr << "missing range slider of name '" << ranges[i].widget << "'\n";
    else {
      range->set_range (ranges[i].min, ranges[i].max);
      range->set_increments (ranges[i].inc, ranges[i].inc_page);
    }
  }

  // connect widget / values from our table
  for (uint i = 0; i < G_N_ELEMENTS (settings); i++) {
    const char *glade_name = settings[i].glade_name;

    if (!glade_name)
      continue;

    switch (settings[i].type) {
    case T_BOOL: {
      Gtk::CheckButton *check = NULL;
      builder->get_widget (glade_name, check);
      if (check)
	check->signal_toggled().connect
          (sigc::bind(sigc::bind(sigc::mem_fun(*this, &Settings::get_from_gui), i), builder));
      break;
    }
    case T_INT:
    case T_FLOAT: {
      Gtk::Widget *w = NULL;
      builder->get_widget (glade_name, w);
      if (!w) {
        std::cerr << "Missing user interface item " << glade_name << "\n";
        break;
      }
      Gtk::SpinButton *spin = dynamic_cast<Gtk::SpinButton *>(w);
      if (spin) {
        spin->signal_value_changed().connect
          (sigc::bind(sigc::bind(sigc::mem_fun(*this, &Settings::get_from_gui), i), builder));
        break;
      }
      Gtk::Range *range = dynamic_cast<Gtk::Range *>(w);
      if (range) {
        range->signal_value_changed().connect
          (sigc::bind(sigc::bind(sigc::mem_fun(*this, &Settings::get_from_gui), i), builder));
        break;
      }
      break;
    }
    case T_STRING: // unimplemented
      break;
    default:
      break;
    }
  }

  // Slicing.ShrinkQuality
  Gtk::ComboBox *combo = NULL;
  builder->get_widget ("Slicing.ShrinkQuality", combo);
  if (combo) {
    Glib::RefPtr<Gtk::ListStore> model;
    Gtk::TreeModelColumnRecord record;
    Gtk::TreeModelColumn<Glib::ustring> column;
    record.add (column);
    model = Gtk::ListStore::create(record);
    model->append()->set_value (0, Glib::ustring("Fast"));
    model->append()->set_value (0, Glib::ustring("Logick"));
    combo->set_model (model);
    combo->pack_start (column);

    combo->signal_changed().connect
      (sigc::bind(sigc::mem_fun(*this, &Settings::get_shrink_from_gui), builder));
  }

  // Colour selectors
  for (uint i = 0; i < G_N_ELEMENTS (colour_selectors); i++) {
    const char *glade_name = colour_selectors[i].glade_name;
    Gdk::Color c;
    Gtk::ColorButton *w = NULL;

    if (!glade_name)
      continue;

    builder->get_widget (glade_name, w);
    if (!w) continue;

    w->signal_color_set().connect
          (sigc::bind(sigc::bind(sigc::mem_fun(*this,
            &Settings::get_colour_from_gui), i), builder));
  }

  // Serial port speed
  Gtk::ComboBoxEntry *portspeed = NULL;
  builder->get_widget ("Hardware.SerialSpeed", portspeed);
  if (portspeed) {
    const guint32 speeds[] = {
        9600, 19200, 38400, 57600, 115200, 230400, 576000
    };

    Glib::RefPtr<Gtk::ListStore> model;
    Gtk::TreeModelColumnRecord record;
    Gtk::TreeModelColumn<Glib::ustring> column;
    record.add (column);
    model = Gtk::ListStore::create(record);
    for (guint i = 0; i < G_N_ELEMENTS(speeds); i++) {
      std::ostringstream val;
      val << speeds[i];
      model->append()->set_value (0, Glib::ustring(val.str()));
    }
    portspeed->set_model (model);
    portspeed->set_text_column (0);

    portspeed->signal_changed().connect
      (sigc::bind(sigc::mem_fun(*this, &Settings::get_port_speed_from_gui), builder));
  }

  /* Update UI with defaults */
  m_signal_update_settings_gui.emit();
}