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

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

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

revision 2641 by schoenebeck, Mon Jun 16 15:24:54 2014 UTC revision 3473 by persson, Sat Feb 16 20:35:46 2019 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2014 Andreas Persson   * Copyright (C) 2006-2017 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 17  Line 17 
17   * 02110-1301 USA.   * 02110-1301 USA.
18   */   */
19    
20    #include "compat.h"
21  #include "dimensionmanager.h"  #include "dimensionmanager.h"
22    
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/dialog.h>  #include <gtkmm/dialog.h>
28  #include <gtkmm/comboboxtext.h>  #include <gtkmm/comboboxtext.h>
29  #include <gtkmm/spinbutton.h>  #include <gtkmm/spinbutton.h>
30  #include <gtkmm/table.h>  #include <gtkmm/label.h>
31    #if USE_GTKMM_GRID
32    # include <gtkmm/grid.h>
33    #else
34    # include <gtkmm/table.h>
35    #endif
36    
37  #include "global.h"  #include "global.h"
38  #include "compat.h"  #include "compat.h"
# Line 236  void IntSetCellRenderer::valueChanged() Line 244  void IntSetCellRenderer::valueChanged()
244  }  }
245    
246  DimensionManager::DimensionManager() :  DimensionManager::DimensionManager() :
247  addButton(Gtk::Stock::ADD), removeButton(Gtk::Stock::REMOVE),  #if HAS_GTKMM_STOCK
248  allRegionsCheckBox(_("All Regions"))      addButton(Gtk::Stock::ADD), removeButton(Gtk::Stock::REMOVE),
249    #else
250        addButton(_("_Add"), true), removeButton(_("_Remove"), true),
251    #endif
252        allRegionsCheckBox(_("All Regions"))
253  {  {
254      ignoreColumnClicked = true;      ignoreColumnClicked = true;
255    
256        if (!Settings::singleton()->autoRestoreWindowDimension) {
257            set_default_size(630, 250);
258            set_position(Gtk::WIN_POS_MOUSE);
259        }
260    
261    #if !HAS_GTKMM_STOCK
262        // see : https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
263        addButton.set_icon_name("list-add");
264        removeButton.set_icon_name("list-remove");
265    #endif
266    
267      set_title(_("Dimensions of selected Region"));      set_title(_("Dimensions of selected Region"));
268      add(vbox);      add(vbox);
269      scrolledWindow.add(treeView);      scrolledWindow.add(treeView);
# Line 248  allRegionsCheckBox(_("All Regions")) Line 271  allRegionsCheckBox(_("All Regions"))
271      scrolledWindow.show();      scrolledWindow.show();
272      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
273      buttonBox.set_layout(Gtk::BUTTONBOX_END);      buttonBox.set_layout(Gtk::BUTTONBOX_END);
274    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
275        buttonBox.set_margin(5);
276    #else
277      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
278    #endif
279      buttonBox.show();      buttonBox.show();
280      buttonBox.pack_start(allRegionsCheckBox, Gtk::PACK_EXPAND_PADDING);      buttonBox.pack_start(allRegionsCheckBox, Gtk::PACK_EXPAND_PADDING);
281      buttonBox.pack_start(addButton, Gtk::PACK_SHRINK);      buttonBox.pack_start(addButton, Gtk::PACK_SHRINK);
# Line 288  allRegionsCheckBox(_("All Regions")) Line 315  allRegionsCheckBox(_("All Regions"))
315          sigc::mem_fun(*this, &DimensionManager::onAllRegionsCheckBoxToggled)          sigc::mem_fun(*this, &DimensionManager::onAllRegionsCheckBoxToggled)
316      );      );
317    
318    #if HAS_GTKMM_SHOW_ALL_CHILDREN
319      show_all_children();      show_all_children();
320        #endif
321      resize(460,300);  
322        Settings::singleton()->showTooltips.get_proxy().signal_changed().connect(
323            sigc::mem_fun(*this, &DimensionManager::on_show_tooltips_changed)
324        );
325        on_show_tooltips_changed();
326    }
327    
328    void DimensionManager::on_show_tooltips_changed() {
329        const bool b = Settings::singleton()->showTooltips;
330    
331        treeView.set_has_tooltip(b);
332        allRegionsCheckBox.set_has_tooltip(b);
333    
334        set_has_tooltip(b);
335  }  }
336    
337  bool DimensionManager::allRegions() const {  bool DimensionManager::allRegions() const {
# Line 319  struct _DimDef { Line 360  struct _DimDef {
360  };  };
361  typedef std::map<gig::dimension_t, _DimDef> _Dimensions;  typedef std::map<gig::dimension_t, _DimDef> _Dimensions;
362    
363  // update all GUI elements according to current gig::Region informations  // update all GUI elements according to current gig::Region information
364  void DimensionManager::refreshManager() {  void DimensionManager::refreshManager() {
365      set_sensitive(false);      set_sensitive(false);
366      refTableModel->clear();      refTableModel->clear();
# Line 384  void DimensionManager::set_region(gig::R Line 425  void DimensionManager::set_region(gig::R
425  }  }
426    
427  void DimensionManager::onColumnClicked() {  void DimensionManager::onColumnClicked() {
428        printf("DimensionManager::onColumnClicked()\n");
429    
430        //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 !
431    
432      //HACK: Prevents that onColumnClicked() gets called multiple times or at times where it is not desired      //HACK: Prevents that onColumnClicked() gets called multiple times or at times where it is not desired
433      if (ignoreColumnClicked) {      if (ignoreColumnClicked) {
434          ignoreColumnClicked = false;          ignoreColumnClicked = false;
435          return;          return;
436      }      }
437    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 18) || GTKMM_MAJOR_VERSION > 2
438        // prevents app to crash if this dialog is closed
439        if (!get_visible())
440            return;
441    #else
442    # warning Your GTKMM version is too old; dimension manager dialog might crash when changing a dimension type !
443    #endif
444    
445    #if (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 3
446        if (!is_visible()) return;
447    #endif
448    
449      Gtk::TreeModel::Path path;      Gtk::TreeModel::Path path;
450      Gtk::TreeViewColumn* focus_column;      Gtk::TreeViewColumn* focus_column;
# Line 396  void DimensionManager::onColumnClicked() Line 452  void DimensionManager::onColumnClicked()
452      //const int row = path[0];      //const int row = path[0];
453      if (focus_column == treeView.get_column(0)) {      if (focus_column == treeView.get_column(0)) {
454          Gtk::TreeModel::iterator it = treeView.get_model()->get_iter(path);          Gtk::TreeModel::iterator it = treeView.get_model()->get_iter(path);
455            if (!it) return;
456          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
457          gig::dimension_t oldType = row[tableModel.m_type];          gig::dimension_t oldType = row[tableModel.m_type];
458    
# Line 413  void DimensionManager::onColumnClicked() Line 470  void DimensionManager::onColumnClicked()
470                  count++;                  count++;
471              }              }
472          }          }
473    #if USE_GTKMM_GRID
474            Gtk::Grid table;
475    #else
476          Gtk::Table table(1, 2);          Gtk::Table table(1, 2);
477    #endif
478          Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START);          Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START);
479          Gtk::ComboBox comboDimType;          Gtk::ComboBox comboDimType;
480          comboDimType.set_model(refComboModel);          comboDimType.set_model(refComboModel);
# Line 421  void DimensionManager::onColumnClicked() Line 482  void DimensionManager::onColumnClicked()
482          comboDimType.pack_start(comboModel.m_type_name);          comboDimType.pack_start(comboModel.m_type_name);
483          table.attach(labelDimType, 0, 1, 0, 1);          table.attach(labelDimType, 0, 1, 0, 1);
484          table.attach(comboDimType, 1, 2, 0, 1);          table.attach(comboDimType, 1, 2, 0, 1);
485    #if USE_GTKMM_BOX
486            dialog.get_content_area()->pack_start(table);
487    #else
488          dialog.get_vbox()->pack_start(table);          dialog.get_vbox()->pack_start(table);
489    #endif
490    
491    #if HAS_GTKMM_STOCK
492          dialog.add_button(Gtk::Stock::OK, 0);          dialog.add_button(Gtk::Stock::OK, 0);
493          dialog.add_button(Gtk::Stock::CANCEL, 1);          dialog.add_button(Gtk::Stock::CANCEL, 1);
494    #else
495            dialog.add_button(_("_OK"), 0);
496            dialog.add_button(_("_Cancel"), 1);
497    #endif
498    #if HAS_GTKMM_SHOW_ALL_CHILDREN
499          dialog.show_all_children();          dialog.show_all_children();
500    #endif
501                    
502          comboDimType.set_active(oldTypeIndex);          comboDimType.set_active(oldTypeIndex);
503    
504          if (!dialog.run()) { // OK selected ...          if (!dialog.run()) { // OK selected ...
505                ignoreColumnClicked = true;
506              Gtk::TreeModel::iterator iterType = comboDimType.get_active();              Gtk::TreeModel::iterator iterType = comboDimType.get_active();
507              if (!iterType) return;              if (!iterType) return;
508              Gtk::TreeModel::Row rowType = *iterType;              Gtk::TreeModel::Row rowType = *iterType;
# Line 438  void DimensionManager::onColumnClicked() Line 511  void DimensionManager::onColumnClicked()
511              gig::dimension_t newType = static_cast<gig::dimension_t>(iTypeID);              gig::dimension_t newType = static_cast<gig::dimension_t>(iTypeID);
512              if (newType == oldType) return;              if (newType == oldType) return;
513              //printf("change 0x%x -> 0x%x\n", oldType, newType);              //printf("change 0x%x -> 0x%x\n", oldType, newType);
             ignoreColumnClicked = true;  
514    
515              // assemble the list of regions where the selected dimension type              // assemble the list of regions where the selected dimension type
516              // shall be changed              // shall be changed
# Line 497  void DimensionManager::onColumnClicked() Line 569  void DimensionManager::onColumnClicked()
569                  msg.run();                  msg.run();
570              }              }
571          }          }
572        } else if (focus_column == treeView.get_column(1) || focus_column == treeView.get_column(2)) {
573            Glib::ustring txt = _("Right-click on a specific dimension zone of the dimension region selector to delete or split that particular dimension zone!");
574            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_INFO);
575            msg.run();
576      }      }
577  }  }
578    
# Line 513  void DimensionManager::addDimension() { Line 589  void DimensionManager::addDimension() {
589              row[comboModel.m_type_name] = sType;              row[comboModel.m_type_name] = sType;
590          }          }
591      }      }
592    #if USE_GTKMM_GRID
593        Gtk::Grid table;
594    #else
595      Gtk::Table table(2, 2);      Gtk::Table table(2, 2);
596    #endif
597      Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START);      Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START);
598      Gtk::ComboBox comboDimType;      Gtk::ComboBox comboDimType;
599      comboDimType.set_model(refComboModel);      comboDimType.set_model(refComboModel);
600      comboDimType.pack_start(comboModel.m_type_id);      comboDimType.pack_start(comboModel.m_type_id);
601      comboDimType.pack_start(comboModel.m_type_name);      comboDimType.pack_start(comboModel.m_type_name);
602      Gtk::Label labelZones(_("Zones:"), Gtk::ALIGN_START);      Gtk::Label labelZones(_("Zones:"), Gtk::ALIGN_START);
603    #if USE_GTKMM_GRID
604        table.attach(labelDimType, 0, 0);
605        table.attach(comboDimType, 1, 0);
606        table.attach(labelZones, 0, 1);
607    #else
608      table.attach(labelDimType, 0, 1, 0, 1);      table.attach(labelDimType, 0, 1, 0, 1);
609      table.attach(comboDimType, 1, 2, 0, 1);      table.attach(comboDimType, 1, 2, 0, 1);
610      table.attach(labelZones, 0, 1, 1, 2);      table.attach(labelZones, 0, 1, 1, 2);
611    #endif
612    
613    #if USE_GTKMM_BOX
614        dialog.get_content_area()->pack_start(table);
615    #else
616      dialog.get_vbox()->pack_start(table);      dialog.get_vbox()->pack_start(table);
617    #endif
618    
619      // number of zones: use a combo box with fix values for gig      // number of zones: use a combo box with fix values for gig
620      // v2 and a spin button for v3      // v2 and a spin button for v3
# Line 553  void DimensionManager::addDimension() { Line 644  void DimensionManager::addDimension() {
644          table.attach(spinZones, 1, 2, 1, 2);          table.attach(spinZones, 1, 2, 1, 2);
645      }      }
646    
647    #if HAS_GTKMM_STOCK
648      dialog.add_button(Gtk::Stock::OK, 0);      dialog.add_button(Gtk::Stock::OK, 0);
649      dialog.add_button(Gtk::Stock::CANCEL, 1);      dialog.add_button(Gtk::Stock::CANCEL, 1);
650    #else
651        dialog.add_button(_("_OK"), 0);
652        dialog.add_button(_("_Cancel"), 1);
653    #endif
654    #if HAS_GTKMM_SHOW_ALL_CHILDREN
655      dialog.show_all_children();      dialog.show_all_children();
656    #endif
657    
658      if (!dialog.run()) { // OK selected ...      if (!dialog.run()) { // OK selected ...
659          Gtk::TreeModel::iterator iterType = comboDimType.get_active();          Gtk::TreeModel::iterator iterType = comboDimType.get_active();

Legend:
Removed from v.2641  
changed lines
  Added in v.3473

  ViewVC Help
Powered by ViewVC