/[svn]/gigedit/trunk/src/gigedit/CombineInstrumentsDialog.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/CombineInstrumentsDialog.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3339 by schoenebeck, Sun Jul 30 18:57:35 2017 UTC revision 3762 by schoenebeck, Wed Apr 1 17:43:49 2020 UTC
# Line 1  Line 1 
1  /*  /*
2      Copyright (c) 2014-2017 Christian Schoenebeck      Copyright (c) 2014-2020 Christian Schoenebeck
3        
4      This file is part of "gigedit" and released under the terms of the      This file is part of "gigedit" and released under the terms of the
5      GNU General Public License version 2.      GNU General Public License version 2.
6  */  */
# Line 20  Line 20 
20  #include <string.h>  #include <string.h>
21    
22  #include <glibmm/ustring.h>  #include <glibmm/ustring.h>
23  #include <gtkmm/stock.h>  #if HAS_GTKMM_STOCK
24    # include <gtkmm/stock.h>
25    #endif
26  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
27  #include <gtkmm/label.h>  #include <gtkmm/label.h>
28  #include <gtk/gtkwidget.h> // for gtk_widget_modify_*()  #include <gtk/gtkwidget.h> // for gtk_widget_modify_*()
# Line 782  static void combineInstruments(std::vect Line 784  static void combineInstruments(std::vect
784  CombineInstrumentsDialog::CombineInstrumentsDialog(Gtk::Window& parent, gig::File* gig)  CombineInstrumentsDialog::CombineInstrumentsDialog(Gtk::Window& parent, gig::File* gig)
785      : ManagedDialog(_("Combine Instruments"), parent, true),      : ManagedDialog(_("Combine Instruments"), parent, true),
786        m_gig(gig), m_fileWasChanged(false), m_newCombinedInstrument(NULL),        m_gig(gig), m_fileWasChanged(false), m_newCombinedInstrument(NULL),
787    #if HAS_GTKMM_STOCK
788        m_cancelButton(Gtk::Stock::CANCEL), m_OKButton(Gtk::Stock::OK),        m_cancelButton(Gtk::Stock::CANCEL), m_OKButton(Gtk::Stock::OK),
789        m_descriptionLabel(), m_tableDimCombo(2, 2), m_comboDimType(),  #else
790          m_cancelButton(_("_Cancel"), true), m_OKButton(_("_OK"), true),
791    #endif
792          m_descriptionLabel(),
793    #if USE_GTKMM_GRID
794          m_tableDimCombo(),
795    #else
796          m_tableDimCombo(2, 2),
797    #endif
798          m_comboDimType(),
799        m_labelDimType(Glib::ustring(_("Combine by Dimension:")) + "  ", Gtk::ALIGN_END)        m_labelDimType(Glib::ustring(_("Combine by Dimension:")) + "  ", Gtk::ALIGN_END)
800  {  {
801      if (!Settings::singleton()->autoRestoreWindowDimension) {      if (!Settings::singleton()->autoRestoreWindowDimension) {
# Line 794  CombineInstrumentsDialog::CombineInstrum Line 806  CombineInstrumentsDialog::CombineInstrum
806      m_scrolledWindow.add(m_treeView);      m_scrolledWindow.add(m_treeView);
807      m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
808    
809    #if USE_GTKMM_BOX
810        get_content_area()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK);
811        get_content_area()->pack_start(m_tableDimCombo, Gtk::PACK_SHRINK);
812        get_content_area()->pack_start(m_scrolledWindow);
813        get_content_area()->pack_start(m_labelOrder, Gtk::PACK_SHRINK);
814        get_content_area()->pack_start(m_iconView, Gtk::PACK_SHRINK);
815        get_content_area()->pack_start(m_buttonBox, Gtk::PACK_SHRINK);
816    #else
817      get_vbox()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK);      get_vbox()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK);
818      get_vbox()->pack_start(m_tableDimCombo, Gtk::PACK_SHRINK);      get_vbox()->pack_start(m_tableDimCombo, Gtk::PACK_SHRINK);
819      get_vbox()->pack_start(m_scrolledWindow);      get_vbox()->pack_start(m_scrolledWindow);
820      get_vbox()->pack_start(m_labelOrder, Gtk::PACK_SHRINK);      get_vbox()->pack_start(m_labelOrder, Gtk::PACK_SHRINK);
821      get_vbox()->pack_start(m_iconView, Gtk::PACK_SHRINK);      get_vbox()->pack_start(m_iconView, Gtk::PACK_SHRINK);
822      get_vbox()->pack_start(m_buttonBox, Gtk::PACK_SHRINK);      get_vbox()->pack_start(m_buttonBox, Gtk::PACK_SHRINK);
823    #endif
824    
825  #if GTKMM_MAJOR_VERSION >= 3  #if GTKMM_MAJOR_VERSION >= 3
826      m_descriptionLabel.set_line_wrap();      m_descriptionLabel.set_line_wrap();
# Line 884  CombineInstrumentsDialog::CombineInstrum Line 905  CombineInstrumentsDialog::CombineInstrum
905      // (this also fixes a bug with GTK 2 which often causes visibility issue      // (this also fixes a bug with GTK 2 which often causes visibility issue
906      //  with the text of the selected item)      //  with the text of the selected item)
907      {      {
908    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
909          Gdk::Color white;          Gdk::Color white;
910    #else
911            Gdk::RGBA white;
912    #endif
913          white.set("#ffffff");          white.set("#ffffff");
914          GtkWidget* widget = (GtkWidget*) m_iconView.gobj();          GtkWidget* widget = (GtkWidget*) m_iconView.gobj();
915    #if GTK_MAJOR_VERSION < 3
916          gtk_widget_modify_base(widget, GTK_STATE_SELECTED, white.gobj());          gtk_widget_modify_base(widget, GTK_STATE_SELECTED, white.gobj());
917          gtk_widget_modify_base(widget, GTK_STATE_ACTIVE, white.gobj());          gtk_widget_modify_base(widget, GTK_STATE_ACTIVE, white.gobj());
918          gtk_widget_modify_bg(widget, GTK_STATE_SELECTED, white.gobj());          gtk_widget_modify_bg(widget, GTK_STATE_SELECTED, white.gobj());
919          gtk_widget_modify_bg(widget, GTK_STATE_ACTIVE, white.gobj());          gtk_widget_modify_bg(widget, GTK_STATE_ACTIVE, white.gobj());
920    #endif
921      }      }
922    
923      m_labelOrder.set_text(_("Order of the instruments to be combined:"));      m_labelOrder.set_text(_("Order of the instruments to be combined:"));
# Line 914  CombineInstrumentsDialog::CombineInstrum Line 941  CombineInstrumentsDialog::CombineInstrum
941      }      }
942    
943      m_buttonBox.set_layout(Gtk::BUTTONBOX_END);      m_buttonBox.set_layout(Gtk::BUTTONBOX_END);
944    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
945        m_buttonBox.set_margin(5);
946    #else
947      m_buttonBox.set_border_width(5);      m_buttonBox.set_border_width(5);
948    #endif
949      m_buttonBox.pack_start(m_cancelButton, Gtk::PACK_SHRINK);      m_buttonBox.pack_start(m_cancelButton, Gtk::PACK_SHRINK);
950      m_buttonBox.pack_start(m_OKButton, Gtk::PACK_SHRINK);      m_buttonBox.pack_start(m_OKButton, Gtk::PACK_SHRINK);
951      m_buttonBox.show();      m_buttonBox.show();
# Line 931  CombineInstrumentsDialog::CombineInstrum Line 962  CombineInstrumentsDialog::CombineInstrum
962          sigc::mem_fun(*this, &CombineInstrumentsDialog::combineSelectedInstruments)          sigc::mem_fun(*this, &CombineInstrumentsDialog::combineSelectedInstruments)
963      );      );
964    
965    #if HAS_GTKMM_SHOW_ALL_CHILDREN
966      show_all_children();      show_all_children();
967    #endif
968    
969        Settings::singleton()->showTooltips.get_proxy().signal_changed().connect(
970            sigc::mem_fun(*this, &CombineInstrumentsDialog::on_show_tooltips_changed)
971        );
972        on_show_tooltips_changed();
973    
974      // show a warning to user if he uses a .gig in v2 format      // show a warning to user if he uses a .gig in v2 format
975      if (gig->pVersion->major < 3) {      if (gig->pVersion->major < 3) {
# Line 951  CombineInstrumentsDialog::CombineInstrum Line 989  CombineInstrumentsDialog::CombineInstrum
989    
990  void CombineInstrumentsDialog::on_order_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)  void CombineInstrumentsDialog::on_order_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
991  {  {
992        #if DEBUG_COMBINE_INSTRUMENTS
993      printf("Drag begin\n");      printf("Drag begin\n");
994        #endif
995      first_call_to_drag_data_get = true;      first_call_to_drag_data_get = true;
996  }  }
997    
998  void CombineInstrumentsDialog::on_order_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context,  void CombineInstrumentsDialog::on_order_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context,
999                                                         Gtk::SelectionData& selection_data, guint, guint)                                                         Gtk::SelectionData& selection_data, guint, guint)
1000  {  {
1001        #if DEBUG_COMBINE_INSTRUMENTS
1002      printf("Drag data get\n");      printf("Drag data get\n");
1003        #endif
1004      if (!first_call_to_drag_data_get) return;      if (!first_call_to_drag_data_get) return;
1005      first_call_to_drag_data_get = false;      first_call_to_drag_data_get = false;
1006    
# Line 978  void CombineInstrumentsDialog::on_order_ Line 1020  void CombineInstrumentsDialog::on_order_
1020          printf("Drag data get: !src\n");          printf("Drag data get: !src\n");
1021          return;          return;
1022      }      }
1023        #if DEBUG_COMBINE_INSTRUMENTS
1024      printf("src=%ld\n", (size_t)src);      printf("src=%ld\n", (size_t)src);
1025        #endif
1026    
1027      // pass the source gig::Instrument as pointer      // pass the source gig::Instrument as pointer
1028      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
# Line 989  void CombineInstrumentsDialog::on_order_ Line 1033  void CombineInstrumentsDialog::on_order_
1033      const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,      const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
1034      const Gtk::SelectionData& selection_data, guint, guint time)      const Gtk::SelectionData& selection_data, guint, guint time)
1035  {  {
1036        #if DEBUG_COMBINE_INSTRUMENTS
1037      printf("Drag data received\n");      printf("Drag data received\n");
1038      if (&selection_data == NULL) {      #endif
         printf("!selection_data\n");  
         return;  
     }  
1039      if (!selection_data.get_data()) {      if (!selection_data.get_data()) {
1040          printf("selection_data.get_data() == NULL\n");          printf("selection_data.get_data() == NULL\n");
1041          return;          return;
# Line 1004  void CombineInstrumentsDialog::on_order_ Line 1046  void CombineInstrumentsDialog::on_order_
1046          printf("!src\n");          printf("!src\n");
1047          return;          return;
1048      }      }
1049      printf("src=%d\n", src);      #if DEBUG_COMBINE_INSTRUMENTS
1050        printf("src=%ld\n", (size_t)src);
1051        #endif
1052    
1053      gig::Instrument* dst = NULL;      gig::Instrument* dst = NULL;
1054      {      {
# Line 1021  void CombineInstrumentsDialog::on_order_ Line 1065  void CombineInstrumentsDialog::on_order_
1065          return;          return;
1066      }      }
1067    
1068        #if DEBUG_COMBINE_INSTRUMENTS
1069      printf("dragdrop received src='%s' dst='%s'\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());      printf("dragdrop received src='%s' dst='%s'\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
1070        #endif
1071    
1072      // swap the two items      // swap the two items
1073      typedef Gtk::TreeModel::Children Children;      typedef Gtk::TreeModel::Children Children;
# Line 1158  void CombineInstrumentsDialog::onSelecti Line 1204  void CombineInstrumentsDialog::onSelecti
1204      {      {
1205          Children allOrdered = m_refOrderModel->children();          Children allOrdered = m_refOrderModel->children();
1206          for (Children::iterator itOrder = allOrdered.begin();          for (Children::iterator itOrder = allOrdered.begin();
1207               itOrder != allOrdered.end(); ++itOrder)               itOrder != allOrdered.end(); )
1208          {          {
1209              Gtk::TreeModel::Row rowOrder = *itOrder;              Gtk::TreeModel::Row rowOrder = *itOrder;
1210              gig::Instrument* instr = rowOrder[m_orderColumns.m_col_instr];              gig::Instrument* instr = rowOrder[m_orderColumns.m_col_instr];
# Line 1170  void CombineInstrumentsDialog::onSelecti Line 1216  void CombineInstrumentsDialog::onSelecti
1216              }              }
1217              goto removeOrderedItem;              goto removeOrderedItem;
1218          nextOrderedItem:          nextOrderedItem:
1219                ++itOrder;
1220              continue;              continue;
1221          removeOrderedItem:          removeOrderedItem:
1222              m_refOrderModel->erase(itOrder);              // postfix increment here to avoid iterator invalidation
1223                m_refOrderModel->erase(itOrder++);
1224          }          }
1225      }      }
1226    
# Line 1216  void CombineInstrumentsDialog::onSelecti Line 1264  void CombineInstrumentsDialog::onSelecti
1264      }      }
1265  }  }
1266    
1267    void CombineInstrumentsDialog::on_show_tooltips_changed() {
1268        const bool b = Settings::singleton()->showTooltips;
1269    
1270        m_treeView.set_has_tooltip(b);
1271        m_iconView.set_has_tooltip(b);
1272    
1273        set_has_tooltip(b);
1274    }
1275    
1276  bool CombineInstrumentsDialog::fileWasChanged() const {  bool CombineInstrumentsDialog::fileWasChanged() const {
1277      return m_fileWasChanged;      return m_fileWasChanged;
1278  }  }

Legend:
Removed from v.3339  
changed lines
  Added in v.3762

  ViewVC Help
Powered by ViewVC