[niepce/gtk3] Fix the click on the cell to rate for Gtk3.



commit 4c7357795d7d2db67beeec5f208d05ccba791111
Author: Hub Figuiere <hub figuiere net>
Date:   Wed Dec 7 22:14:13 2011 -0800

    Fix the click on the cell to rate for Gtk3.

 src/fwk/toolkit/Makefile.am               |    1 +
 src/fwk/toolkit/widgets/imagegridview.cpp |   55 +++++++++++++++++++
 src/fwk/toolkit/widgets/imagegridview.hpp |   83 +++++++++++++++++++++++++++++
 src/niepce/ui/gridviewmodule.cpp          |   40 ++++++++------
 src/niepce/ui/gridviewmodule.hpp          |    3 +-
 src/niepce/ui/librarycellrenderer.cpp     |   22 ++++----
 src/niepce/ui/librarycellrenderer.hpp     |    9 ++-
 7 files changed, 180 insertions(+), 33 deletions(-)
---
diff --git a/src/fwk/toolkit/Makefile.am b/src/fwk/toolkit/Makefile.am
index 807f4bf..e75180e 100644
--- a/src/fwk/toolkit/Makefile.am
+++ b/src/fwk/toolkit/Makefile.am
@@ -36,6 +36,7 @@ libniepceframework_a_SOURCES = configuration.hpp configuration.cpp \
 	widgets/editablehscale.hpp widgets/editablehscale.cpp \
 	widgets/dock.cpp widgets/dock.hpp \
 	widgets/notabtextview.hpp widgets/notabtextview.cpp \
+	widgets/imagegridview.hpp widgets/imagegridview.cpp \
 	dockable.hpp dockable.cpp \
 	metadatawidget.hpp metadatawidget.cpp \
 	undo.hpp undo.cpp \
diff --git a/src/fwk/toolkit/widgets/imagegridview.cpp b/src/fwk/toolkit/widgets/imagegridview.cpp
new file mode 100644
index 0000000..1edd487
--- /dev/null
+++ b/src/fwk/toolkit/widgets/imagegridview.cpp
@@ -0,0 +1,55 @@
+/*
+ * niepce - fwk/toolkit/widgets/imagegridview.cpp
+ *
+ * Copyright (C) 2011 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "fwk/base/debug.hpp"
+#include "imagegridview.hpp"
+
+namespace fwk {
+
+void ClickableCellRenderer::hit(int x, int y)
+{
+  m_x = x;
+  m_y = y;
+  m_hit = true;
+}
+
+ImageGridView::ImageGridView()
+  : Gtk::IconView()
+{
+}
+
+bool ImageGridView::on_button_press_event(GdkEventButton *event)
+{
+  bool ret = Gtk::IconView::on_button_press_event(event);
+
+  Gtk::CellRenderer* cell = NULL;
+  bool found = get_item_at_pos(event->x, event->y, cell);
+  if(found) {
+    ClickableCellRenderer* clickable_cell = dynamic_cast<ClickableCellRenderer*>(cell);
+    
+    if(clickable_cell) {
+      DBG_OUT("clickable cell");
+      clickable_cell->hit(event->x, event->y);
+    }
+  }
+
+  return ret;
+}
+
+}
diff --git a/src/fwk/toolkit/widgets/imagegridview.hpp b/src/fwk/toolkit/widgets/imagegridview.hpp
new file mode 100644
index 0000000..fea5024
--- /dev/null
+++ b/src/fwk/toolkit/widgets/imagegridview.hpp
@@ -0,0 +1,83 @@
+/*
+ * niepce - fwk/toolkit/widgets/imagegridview.hpp
+ *
+ * Copyright (C) 2011 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IMAGE_GRID_VIEW_H__
+#define IMAGE_GRID_VIEW_H__
+
+#include <gtkmm/iconview.h>
+#include <gtkmm/cellareabox.h>
+
+namespace fwk {
+
+/**
+ * Clickable Cell Renderer
+ * To work around https://bugzilla.gnome.org/show_bug.cgi?id=664368
+ */
+class ClickableCellRenderer
+{
+public:
+  ClickableCellRenderer()
+    : m_x(0)
+    , m_y(0)
+    , m_hit(false)
+  {
+  }
+  /**
+   * Hit.
+   */
+  void hit(int x, int y);
+  int x() const 
+  {
+    return m_x;
+  }
+  int y() const
+  {
+    return m_y;
+  }
+  bool is_hit() const
+  {
+    return m_hit;
+  }
+  void reset_hit()
+  {
+    m_hit = false;
+  }
+private:
+  int m_x, m_y;
+  bool m_hit;
+};
+
+class ImageGridView
+  : public Gtk::IconView
+{
+public:
+  ImageGridView();
+
+  /**
+   * Used to work around the activate that don't pass an event.
+   * https://bugzilla.gnome.org/show_bug.cgi?id=664368
+   */
+  virtual bool on_button_press_event(GdkEventButton *event);
+
+private:
+};
+
+}
+
+#endif
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index 20b60b1..6f7fe89 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -41,6 +41,8 @@ GridViewModule::GridViewModule(const IModuleShell & shell,
   : m_shell(shell)
   , m_model(store)
   , m_uidataprovider(NULL)
+  , m_librarylistview(NULL)
+  , m_dock(NULL)
 {
     m_uidataprovider = m_shell.getLibraryClient()->getDataProvider();
     DBG_ASSERT(m_uidataprovider, "provider is NULL");
@@ -100,27 +102,29 @@ Gtk::Widget * GridViewModule::buildWidget(const Glib::RefPtr<Gtk::UIManager> & m
     return m_widget;
   }
   m_widget = &m_lib_splitview;
-  m_librarylistview.set_model(m_model);
-  m_librarylistview.set_selection_mode(Gtk::SELECTION_SINGLE);
-  m_librarylistview.property_row_spacing() = 0;
-  m_librarylistview.property_column_spacing() = 0;
-  m_librarylistview.property_spacing() = 0;
-  m_librarylistview.property_margin() = 0;
-
-  m_librarylistview.signal_button_press_event()
+  m_librarylistview = Gtk::manage(new fwk::ImageGridView());
+  m_librarylistview->set_model(m_model);
+  m_librarylistview->set_selection_mode(Gtk::SELECTION_SINGLE);
+  m_librarylistview->property_row_spacing() = 0;
+  m_librarylistview->property_column_spacing() = 0;
+  m_librarylistview->property_spacing() = 0;
+  m_librarylistview->property_margin() = 0;
+
+  m_librarylistview->signal_button_press_event()
       .connect(sigc::mem_fun(*this,  &GridViewModule::on_librarylistview_click));
 
   // the main cell
   LibraryCellRenderer * libcell = Gtk::manage(new LibraryCellRenderer(m_uidataprovider));
   libcell->signal_rating_changed.connect(sigc::mem_fun(*this, &GridViewModule::on_rating_changed));
 
-  m_librarylistview.pack_start(*libcell, FALSE);
-  m_librarylistview.add_attribute(*libcell, "pixbuf", 
+  Glib::RefPtr<Gtk::CellArea> cell_area = m_librarylistview->property_cell_area();
+  cell_area->pack_start(*libcell, FALSE);
+  cell_area->add_attribute(*libcell, "pixbuf", 
                                   m_model->columns().m_pix.index());
-  m_librarylistview.add_attribute(*libcell, "libfile", 
+  cell_area->add_attribute(*libcell, "libfile", 
                                   m_model->columns().m_libfile.index());
 
-  m_scrollview.add(m_librarylistview);
+  m_scrollview.add(*m_librarylistview);
   m_scrollview.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
   m_lib_splitview.pack1(m_scrollview);
   m_dock = new fwk::Dock();
@@ -150,7 +154,7 @@ void GridViewModule::set_active(bool /*active*/)
 
 Gtk::IconView * GridViewModule::image_list()
 { 
-    return & m_librarylistview; 
+    return m_librarylistview; 
 }
 
 eng::library_id_t GridViewModule::get_selected()
@@ -158,7 +162,7 @@ eng::library_id_t GridViewModule::get_selected()
 	eng::library_id_t id = 0;
     Glib::RefPtr<Gtk::TreeSelection> selection;
 
-    std::vector<Gtk::TreePath> paths = m_librarylistview.get_selected_items();
+    std::vector<Gtk::TreePath> paths = m_librarylistview->get_selected_items();
     if(!paths.empty()) {
         Gtk::TreePath path(*(paths.begin()));
         DBG_OUT("found path %s", path.to_string().c_str());
@@ -180,10 +184,10 @@ void GridViewModule::select_image(eng::library_id_t id)
     DBG_OUT("library select %Ld", id);
     Gtk::TreePath path = m_model->get_path_from_id(id);
     if(path) {
-      m_librarylistview.select_path(path);
+      m_librarylistview->select_path(path);
     }
     else {
-      m_librarylistview.unselect_all();
+      m_librarylistview->unselect_all();
     }
 }
 
@@ -210,8 +214,8 @@ bool GridViewModule::on_librarylistview_click(GdkEventButton *e)
     Gtk::TreeModel::Path path;
     Gtk::CellRenderer * renderer = NULL;
     DBG_OUT("click (%f, %f)", x, y);
-    m_librarylistview.convert_widget_to_bin_window_coords(x, y, bx, by);
-    if(m_librarylistview.get_item_at_pos(bx, by, path, renderer)){
+    m_librarylistview->convert_widget_to_bin_window_coords(x, y, bx, by);
+    if(m_librarylistview->get_item_at_pos(bx, by, path, renderer)){
         DBG_OUT("found an item");
 
         return true;
diff --git a/src/niepce/ui/gridviewmodule.hpp b/src/niepce/ui/gridviewmodule.hpp
index b7ccdff..ecec50a 100644
--- a/src/niepce/ui/gridviewmodule.hpp
+++ b/src/niepce/ui/gridviewmodule.hpp
@@ -30,6 +30,7 @@
 
 #include "fwk/base/propertybag.hpp"
 #include "engine/db/library.hpp"
+#include "fwk/toolkit/widgets/imagegridview.hpp"
 #include "niepce/ui/ilibrarymodule.hpp"
 #include "niepce/ui/imoduleshell.hpp"
 #include "niepce/ui/metadatapanecontroller.hpp"
@@ -84,7 +85,7 @@ private:
   libraryclient::UIDataProvider *m_uidataprovider;
 
   // library split view
-  Gtk::IconView                m_librarylistview;
+  fwk::ImageGridView*          m_librarylistview;
   Gtk::ScrolledWindow          m_scrollview;
   MetaDataPaneController::Ptr  m_metapanecontroller;
   Gtk::HPaned                  m_lib_splitview;
diff --git a/src/niepce/ui/librarycellrenderer.cpp b/src/niepce/ui/librarycellrenderer.cpp
index f8b6f17..1f11580 100644
--- a/src/niepce/ui/librarycellrenderer.cpp
+++ b/src/niepce/ui/librarycellrenderer.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/librarycellrenderer.cpp
  *
- * Copyright (C) 2008 Hubert Figuiere
+ * Copyright (C) 2008,2011 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,9 +20,6 @@
 
 #include <stdint.h>
 
-#include <gdkmm.h>
-#include <gtkmm.h>
-
 #include "fwk/base/debug.hpp"
 #include "fwk/toolkit/widgets/ratinglabel.hpp"
 #include "fwk/toolkit/gdkutils.hpp"
@@ -294,16 +291,19 @@ LibraryCellRenderer::render_vfunc(const Cairo::RefPtr<Cairo::Context>& cr,
 
 
 bool
-LibraryCellRenderer::on_click(GdkEventButton *event, const GdkRectangle & cell_area)
+LibraryCellRenderer::activate_vfunc(GdkEvent *event, Gtk::Widget & ,
+                                    const Glib::ustring &, const Gdk::Rectangle& /*bg*/,
+                                    const Gdk::Rectangle & cell_area, Gtk::CellRendererState)
 {
-    DBG_OUT("On click. Event type of %d", event->type);
-    if(event->type == GDK_BUTTON_PRESS) {
-        GdkEventButton *bevt = (GdkEventButton*)event;
+    DBG_OUT("On click. Event %p", event);
+    if(this->ClickableCellRenderer::is_hit()) {
+
+        this->ClickableCellRenderer::reset_hit();
 
         // hit test with the rating region
         unsigned int xpad = Gtk::CellRenderer::property_xpad();
         unsigned int ypad = Gtk::CellRenderer::property_ypad();
-        GdkRectangle r = cell_area;
+        GdkRectangle r = *cell_area.gobj();
         r.x += xpad;
         r.y += ypad;
 
@@ -315,8 +315,8 @@ LibraryCellRenderer::on_click(GdkEventButton *event, const GdkRectangle & cell_a
         rect.y = r.y + r.height - rh - CELL_PADDING;
         rect.width = rw;
         rect.height = rh;
-        x = bevt->x;
-        y = bevt->y;
+        x = this->ClickableCellRenderer::x();
+        y = this->ClickableCellRenderer::y();
         DBG_OUT("r(%d, %d, %d, %d) p(%f, %f)", rect.x, rect.y,
                 rect.width, rect.height, x, y);
         bool hit = (rect.x <= x) && (rect.x + rect.width >= x) 
diff --git a/src/niepce/ui/librarycellrenderer.hpp b/src/niepce/ui/librarycellrenderer.hpp
index 4e27663..3d18c1b 100644
--- a/src/niepce/ui/librarycellrenderer.hpp
+++ b/src/niepce/ui/librarycellrenderer.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/librarycellrenderer.h
  *
- * Copyright (C) 2008 Hubert Figuiere
+ * Copyright (C) 2008,2011 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@
 
 #include "engine/db/libfile.hpp"
 #include "engine/db/label.hpp"
+#include "fwk/toolkit/widgets/imagegridview.hpp"
 
 namespace libraryclient {
 class UIDataProvider;
@@ -37,6 +38,7 @@ namespace ui {
 
 class LibraryCellRenderer
 	: public Gtk::CellRendererPixbuf
+        , public fwk::ClickableCellRenderer
 {
 public:
     LibraryCellRenderer(libraryclient::UIDataProvider *provider);
@@ -50,8 +52,9 @@ public:
                                const Gdk::Rectangle& cell_area, 
                                Gtk::CellRendererState flags);
     /** call when the cell is clicked */
-    bool on_click(GdkEventButton *event, const GdkRectangle & cell_area);
-
+    virtual bool activate_vfunc(GdkEvent* event, Gtk::Widget& widget,const Glib::ustring & path,
+                                const Gdk::Rectangle& background_area, 
+                                const Gdk::Rectangle& cell_area, Gtk::CellRendererState flags);
     void set_size(int _size)
         { m_size = _size; }
     int size() const



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]