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

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

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

revision 3307 by schoenebeck, Tue Jul 11 23:06:38 2017 UTC revision 3460 by persson, Sat Feb 2 07:48:50 2019 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2017 Andreas Persson   * Copyright (C) 2006-2019 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 18  Line 18 
18   */   */
19    
20  #include "global.h"  #include "global.h"
21    #include "compat.h"
22    #include "Settings.h"
23  #include <gtkmm/box.h>  #include <gtkmm/box.h>
24  #include "dimregionchooser.h"  #include "dimregionchooser.h"
25  #include <cairomm/context.h>  #include <cairomm/context.h>
26  #include <cairomm/surface.h>  #include <cairomm/surface.h>
27  #include <gdkmm/cursor.h>  #include <gdkmm/cursor.h>
28  #include <gdkmm/general.h>  #include <gdkmm/general.h>
29    #if HAS_GDKMM_SEAT
30    # include <gdkmm/seat.h>
31    #endif
32  #include <glibmm/stringutils.h>  #include <glibmm/stringutils.h>
33  #include <gtkmm/stock.h>  #if HAS_GTKMM_STOCK
34    # include <gtkmm/stock.h>
35    #endif
36  #include <glibmm/ustring.h>  #include <glibmm/ustring.h>
37  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
38  #include <assert.h>  #include <assert.h>
# Line 104  DimRegionChooser::DimRegionChooser(Gtk:: Line 111  DimRegionChooser::DimRegionChooser(Gtk::
111          }          }
112    
113          Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create(          Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create(
114    #if HAS_CAIROMM_CPP11_ENUMS
115                this->blueHatchedPatternARGB->get_pixels(), Cairo::Surface::Format::ARGB32, width, height, stride
116    #else
117              this->blueHatchedPatternARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride              this->blueHatchedPatternARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride
118    #endif
119          );          );
120          this->blueHatchedSurfacePattern = Cairo::SurfacePattern::create(imageSurface);          this->blueHatchedSurfacePattern = Cairo::SurfacePattern::create(imageSurface);
121    #if HAS_CAIROMM_CPP11_ENUMS
122            this->blueHatchedSurfacePattern->set_extend(Cairo::Pattern::Extend::REPEAT);
123    #else
124          this->blueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT);          this->blueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT);
125    #endif
126      }      }
127    
128      // create blue hatched pattern 2      // create blue hatched pattern 2
# Line 134  DimRegionChooser::DimRegionChooser(Gtk:: Line 149  DimRegionChooser::DimRegionChooser(Gtk::
149          }          }
150    
151          Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create(          Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create(
152    #if HAS_CAIROMM_CPP11_ENUMS
153                this->blueHatchedPattern2ARGB->get_pixels(), Cairo::Surface::Format::ARGB32, width, height, stride
154    #else
155              this->blueHatchedPattern2ARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride              this->blueHatchedPattern2ARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride
156    #endif
157          );          );
158          this->blueHatchedSurfacePattern2 = Cairo::SurfacePattern::create(imageSurface);          this->blueHatchedSurfacePattern2 = Cairo::SurfacePattern::create(imageSurface);
159    #if HAS_CAIROMM_CPP11_ENUMS
160            this->blueHatchedSurfacePattern2->set_extend(Cairo::Pattern::Extend::REPEAT);
161    #else
162          this->blueHatchedSurfacePattern2->set_extend(Cairo::EXTEND_REPEAT);          this->blueHatchedSurfacePattern2->set_extend(Cairo::EXTEND_REPEAT);
163    #endif
164      }      }
165    
166      // create gray blue hatched pattern      // create gray blue hatched pattern
# Line 164  DimRegionChooser::DimRegionChooser(Gtk:: Line 187  DimRegionChooser::DimRegionChooser(Gtk::
187          }          }
188    
189          Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create(          Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create(
190    #if HAS_CAIROMM_CPP11_ENUMS
191                this->grayBlueHatchedPatternARGB->get_pixels(), Cairo::Surface::Format::ARGB32, width, height, stride
192    #else
193              this->grayBlueHatchedPatternARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride              this->grayBlueHatchedPatternARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride
194    #endif
195          );          );
196          this->grayBlueHatchedSurfacePattern = Cairo::SurfacePattern::create(imageSurface);          this->grayBlueHatchedSurfacePattern = Cairo::SurfacePattern::create(imageSurface);
197    #if HAS_CAIROMM_CPP11_ENUMS
198            this->grayBlueHatchedSurfacePattern->set_extend(Cairo::Pattern::Extend::REPEAT);
199    #else
200          this->grayBlueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT);          this->grayBlueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT);
201    #endif
202      }      }
203    
204      instrument = 0;      instrument = 0;
# Line 187  DimRegionChooser::DimRegionChooser(Gtk:: Line 218  DimRegionChooser::DimRegionChooser(Gtk::
218      const Glib::ustring txtUseCheckBoxAllRegions =      const Glib::ustring txtUseCheckBoxAllRegions =
219          _("Use checkbox 'all regions' to control whether this should apply to all regions.");          _("Use checkbox 'all regions' to control whether this should apply to all regions.");
220    
221      actionGroup = Gtk::ActionGroup::create();      actionGroup = ActionGroup::create();
222      actionSplitDimZone = Gtk::Action::create("SplitDimZone", _("Split Dimensions Zone"), txtUseCheckBoxAllRegions);  #if USE_GLIB_ACTION
223        actionSplitDimZone = actionGroup->add_action(
224            "SplitDimZone", sigc::mem_fun(*this, &DimRegionChooser::split_dimension_zone)
225        );
226        actionDeleteDimZone = actionGroup->add_action(
227             "DeleteDimZone", sigc::mem_fun(*this, &DimRegionChooser::delete_dimension_zone)
228         );
229        insert_action_group("PopupMenuInsideDimRegion", actionGroup);
230    #else
231        actionSplitDimZone = Action::create("SplitDimZone", _("Split Dimensions Zone"), txtUseCheckBoxAllRegions);
232      actionSplitDimZone->set_tooltip(txtUseCheckBoxAllRegions); //FIXME: doesn't work? why???      actionSplitDimZone->set_tooltip(txtUseCheckBoxAllRegions); //FIXME: doesn't work? why???
233      actionGroup->add(      actionGroup->add(
234          actionSplitDimZone,          actionSplitDimZone,
# Line 200  DimRegionChooser::DimRegionChooser(Gtk:: Line 240  DimRegionChooser::DimRegionChooser(Gtk::
240          actionDeleteDimZone,          actionDeleteDimZone,
241          sigc::mem_fun(*this, &DimRegionChooser::delete_dimension_zone)          sigc::mem_fun(*this, &DimRegionChooser::delete_dimension_zone)
242      );      );
243    #endif
244    
245    #if USE_GTKMM_BUILDER
246        uiManager = Gtk::Builder::create();
247        Glib::ustring ui_info =
248            "<interface>"
249            "  <menu id='menu-PopupMenuInsideDimRegion'>"
250            "    <section>"
251            "      <item id='item-split'>"
252            "        <attribute name='label' translatable='yes'>Split Dimensions Zone</attribute>"
253            "        <attribute name='action'>PopupMenuInsideDimRegion.SplitDimZone</attribute>"
254            "      </item>"
255            "      <item id='item-delete'>"
256            "        <attribute name='label' translatable='yes'>Delete Dimension Zone</attribute>"
257            "        <attribute name='action'>PopupMenuInsideDimRegion.DeleteDimZone</attribute>"
258            "      </item>"
259            "    </section>"
260            "  </menu>"
261            "</interface>";
262        uiManager->add_from_string(ui_info);
263    
264        popup_menu_inside_dimregion = new Gtk::Menu(
265            Glib::RefPtr<Gio::Menu>::cast_dynamic(
266                uiManager->get_object("menu-PopupMenuInsideDimRegion")
267            )
268        );
269    #else
270      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
271      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
272      Glib::ustring ui_info =      Glib::ustring ui_info =
# Line 220  DimRegionChooser::DimRegionChooser(Gtk:: Line 286  DimRegionChooser::DimRegionChooser(Gtk::
286  //     popup_menu_outside_dimregion = dynamic_cast<Gtk::Menu*>(  //     popup_menu_outside_dimregion = dynamic_cast<Gtk::Menu*>(
287  //         uiManager->get_widget("/PopupMenuOutsideDimRegion"));  //         uiManager->get_widget("/PopupMenuOutsideDimRegion"));
288    
289    #endif // USE_GTKMM_BUILDER
290    
291    
292    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
293    # warning GTKMM4 event registration code missing for dimregionchooser!
294        //add_events(Gdk::EventMask::BUTTON_PRESS_MASK);
295    #else
296      add_events(Gdk::BUTTON_PRESS_MASK | Gdk::POINTER_MOTION_MASK |      add_events(Gdk::BUTTON_PRESS_MASK | Gdk::POINTER_MOTION_MASK |
297                 Gdk::POINTER_MOTION_HINT_MASK);                 Gdk::POINTER_MOTION_HINT_MASK);
298    #endif
299    
300      labels_changed = true;      labels_changed = true;
301    
# Line 229  DimRegionChooser::DimRegionChooser(Gtk:: Line 303  DimRegionChooser::DimRegionChooser(Gtk::
303          "Right click here for options on altering dimension zones. Press and "          "Right click here for options on altering dimension zones. Press and "
304          "hold CTRL key for selecting multiple dimension zones simultaniously."          "hold CTRL key for selecting multiple dimension zones simultaniously."
305      ));      ));
306    
307        Settings::singleton()->showTooltips.get_proxy().signal_changed().connect(
308            sigc::mem_fun(*this, &DimRegionChooser::on_show_tooltips_changed)
309        );
310        on_show_tooltips_changed();
311            
312      window.signal_key_press_event().connect(      window.signal_key_press_event().connect(
313          sigc::mem_fun(*this, &DimRegionChooser::onKeyPressed)          sigc::mem_fun(*this, &DimRegionChooser::onKeyPressed)
# Line 242  DimRegionChooser::~DimRegionChooser() Line 321  DimRegionChooser::~DimRegionChooser()
321  {  {
322  }  }
323    
324    void DimRegionChooser::on_show_tooltips_changed() {
325        const bool b = Settings::singleton()->showTooltips;
326    
327        set_has_tooltip(b);
328    }
329    
330  void DimRegionChooser::setModifyBothChannels(bool b) {  void DimRegionChooser::setModifyBothChannels(bool b) {
331      modifybothchannels = b;      modifybothchannels = b;
332      // redraw required parts      // redraw required parts
# Line 257  void DimRegionChooser::setModifyAllDimen Line 342  void DimRegionChooser::setModifyAllDimen
342  void DimRegionChooser::setModifyAllRegions(bool b) {  void DimRegionChooser::setModifyAllRegions(bool b) {
343      modifyallregions = b;      modifyallregions = b;
344    
345    #if USE_GTKMM_BUILDER
346        auto menuItemSplit = Glib::RefPtr<Gio::MenuItem>::cast_dynamic(
347            uiManager->get_object("item-split")
348        );
349        auto menuItemDelete = Glib::RefPtr<Gio::MenuItem>::cast_dynamic(
350            uiManager->get_object("item-delete")
351        );
352        menuItemDelete->set_label(b ? _("Delete Dimension Zone [ALL REGIONS]") : _("Delete Dimension Zone"));
353        menuItemSplit->set_label(b ? _("Split Dimensions Zone [ALL REGIONS]") : _("Split Dimensions Zone"));
354    #else
355      actionDeleteDimZone->set_label(b ? _("Delete Dimension Zone [ALL REGIONS]") : _("Delete Dimension Zone"));      actionDeleteDimZone->set_label(b ? _("Delete Dimension Zone [ALL REGIONS]") : _("Delete Dimension Zone"));
356      actionSplitDimZone->set_label(b ? _("Split Dimensions Zone [ALL REGIONS]") : _("Split Dimensions Zone"));      actionSplitDimZone->set_label(b ? _("Split Dimensions Zone [ALL REGIONS]") : _("Split Dimensions Zone"));
357    #endif
358    
359      // redraw required parts      // redraw required parts
360      queue_draw();      queue_draw();
# Line 434  bool DimRegionChooser::on_draw(const Cai Line 530  bool DimRegionChooser::on_draw(const Cai
530                      const Gdk::Color fg = get_style()->get_fg(get_state());                      const Gdk::Color fg = get_style()->get_fg(get_state());
531  #else  #else
532                      const Gdk::RGBA fg =                      const Gdk::RGBA fg =
533    # if GTKMM_MAJOR_VERSION >= 3
534                            get_style_context()->get_color();
535    # else
536                          get_style_context()->get_color(get_state_flags());                          get_style_context()->get_color(get_state_flags());
537    # endif
538  #endif  #endif
539                      Gdk::Cairo::set_source_rgba(cr, fg);                      Gdk::Cairo::set_source_rgba(cr, fg);
540                      cr->move_to(4, int(y + (h - text_h) / 2 + 0.5));                      cr->move_to(4, int(y + (h - text_h) / 2 + 0.5));
# Line 919  bool DimRegionChooser::on_button_release Line 1019  bool DimRegionChooser::on_button_release
1019  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1020          get_window()->pointer_ungrab(event->time);          get_window()->pointer_ungrab(event->time);
1021  #else  #else
1022    # if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 20)
1023          Glib::wrap(event->device, true)->ungrab(event->time);          Glib::wrap(event->device, true)->ungrab(event->time);
1024    # else
1025            Glib::wrap(event->device, true)->get_seat()->ungrab();
1026    # endif
1027  #endif  #endif
1028          resize.active = false;          resize.active = false;
1029    
# Line 948  bool DimRegionChooser::on_button_press_e Line 1052  bool DimRegionChooser::on_button_press_e
1052                                         Gdk::Cursor(Gdk::SB_H_DOUBLE_ARROW),                                         Gdk::Cursor(Gdk::SB_H_DOUBLE_ARROW),
1053                                         event->time);                                         event->time);
1054  #else  #else
1055    # if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 20)
1056              Glib::wrap(event->device, true)->grab(get_window(),              Glib::wrap(event->device, true)->grab(get_window(),
1057                                                    Gdk::OWNERSHIP_NONE,                                                    Gdk::OWNERSHIP_NONE,
1058                                                    false,                                                    false,
# Line 956  bool DimRegionChooser::on_button_press_e Line 1061  bool DimRegionChooser::on_button_press_e
1061                                                    Gdk::POINTER_MOTION_HINT_MASK,                                                    Gdk::POINTER_MOTION_HINT_MASK,
1062                                                    Gdk::Cursor::create(Gdk::SB_H_DOUBLE_ARROW),                                                    Gdk::Cursor::create(Gdk::SB_H_DOUBLE_ARROW),
1063                                                    event->time);                                                    event->time);
1064    # else
1065                Glib::wrap(event->device, true)->get_seat()->grab(
1066                    get_window(),
1067                    Gdk::SeatCapabilities::SEAT_CAPABILITY_ALL_POINTING,
1068                    false,
1069                    Gdk::Cursor::create(
1070                        Glib::wrap(event->device, true)->get_seat()->get_display(),
1071                        Gdk::SB_H_DOUBLE_ARROW
1072                    ),
1073                    reinterpret_cast<GdkEvent*>(event)
1074                );
1075    # endif
1076  #endif  #endif
1077              resize.active = true;              resize.active = true;
1078          } else {          } else {
# Line 1048  bool DimRegionChooser::on_motion_notify_ Line 1165  bool DimRegionChooser::on_motion_notify_
1165  {  {
1166      Glib::RefPtr<Gdk::Window> window = get_window();      Glib::RefPtr<Gdk::Window> window = get_window();
1167      int x, y;      int x, y;
1168    #if HAS_GDKMM_SEAT
1169        x = event->x;
1170        y = event->y;
1171        Gdk::ModifierType state = Gdk::ModifierType(event->state);
1172    #else
1173      Gdk::ModifierType state = Gdk::ModifierType(0);      Gdk::ModifierType state = Gdk::ModifierType(0);
1174      window->get_pointer(x, y, state);      window->get_pointer(x, y, state);
1175    #endif
1176    
1177      if (resize.active) {      if (resize.active) {
1178          int w = get_width();          int w = get_width();
# Line 1085  bool DimRegionChooser::on_motion_notify_ Line 1208  bool DimRegionChooser::on_motion_notify_
1208  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1209                  window->set_cursor(Gdk::Cursor(Gdk::SB_H_DOUBLE_ARROW));                  window->set_cursor(Gdk::Cursor(Gdk::SB_H_DOUBLE_ARROW));
1210  #else  #else
1211                  window->set_cursor(Gdk::Cursor::create(Gdk::SB_H_DOUBLE_ARROW));                  window->set_cursor(
1212    # if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 20)
1213                        Gdk::Cursor::create(Gdk::SB_H_DOUBLE_ARROW)
1214    # else
1215                        Gdk::Cursor::create(
1216                            Glib::wrap(event->device, true)->get_seat()->get_display(),
1217                            Gdk::SB_H_DOUBLE_ARROW
1218                        )
1219    # endif
1220                    );
1221  #endif  #endif
1222                  cursor_is_resize = true;                  cursor_is_resize = true;
1223              }              }
# Line 1359  static const guint primaryKeyR = Line 1491  static const guint primaryKeyR =
1491      GDK_KEY_Control_R;      GDK_KEY_Control_R;
1492      #endif      #endif
1493    
1494    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
1495    bool DimRegionChooser::onKeyPressed(Gdk::EventKey& _key) {
1496        GdkEventKey* key = _key.gobj();
1497    #else
1498  bool DimRegionChooser::onKeyPressed(GdkEventKey* key) {  bool DimRegionChooser::onKeyPressed(GdkEventKey* key) {
1499    #endif
1500      //printf("key down 0x%x\n", key->keyval);      //printf("key down 0x%x\n", key->keyval);
1501      if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R)      if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R)
1502          multiSelectKeyDown = true;          multiSelectKeyDown = true;
# Line 1380  bool DimRegionChooser::onKeyPressed(GdkE Line 1517  bool DimRegionChooser::onKeyPressed(GdkE
1517      return false;      return false;
1518  }  }
1519    
1520    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
1521    bool DimRegionChooser::onKeyReleased(Gdk::EventKey& _key) {
1522        GdkEventKey* key = _key.gobj();
1523    #else
1524  bool DimRegionChooser::onKeyReleased(GdkEventKey* key) {  bool DimRegionChooser::onKeyReleased(GdkEventKey* key) {
1525    #endif
1526      //printf("key up 0x%x\n", key->keyval);      //printf("key up 0x%x\n", key->keyval);
1527      if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R)      if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R)
1528          multiSelectKeyDown = false;          multiSelectKeyDown = false;
# Line 1479  void DimRegionChooser::select_dimzone_by Line 1621  void DimRegionChooser::select_dimzone_by
1621          return;          return;
1622      }      }
1623    
1624      if (maindimcase.empty()) {      // commented out: re-evaluate maindimcase, since it might not been reset from a previous instrument which causes errors if it got different dimension types
1625        //if (maindimcase.empty()) {
1626          maindimcase = dimensionCaseOf(region->pDimensionRegions[maindimregno]);          maindimcase = dimensionCaseOf(region->pDimensionRegions[maindimregno]);
1627          if (maindimcase.empty()) {          if (maindimcase.empty()) {
1628              printf("caseOfDimregion(%d) -> empty\n", maindimregno);              printf("caseOfDimregion(%d) -> empty\n", maindimregno);
1629              return;              return;
1630          }          }
1631      }      //}
1632    
1633      int z = (dir > 0) ? maindimcase[maindimtype] + 1 : maindimcase[maindimtype] - 1;      int z = (dir > 0) ? maindimcase[maindimtype] + 1 : maindimcase[maindimtype] - 1;
1634      if (z < 0) z = 0;      if (z < 0) z = 0;

Legend:
Removed from v.3307  
changed lines
  Added in v.3460

  ViewVC Help
Powered by ViewVC