[niepce] rust+ui: image grid view widget



commit accb88434ec8ea8ec5f11b7083defcaf40b31dee
Author: Hubert Figuière <hub figuiere net>
Date:   Wed Jan 29 00:49:47 2020 -0500

    rust+ui: image grid view widget

 examples/widget-test.rs                   |   6 +-
 src/Makefile.am                           |   1 +
 src/fwk/toolkit/Makefile.am               |   1 -
 src/fwk/toolkit/widgets/imagegridview.cpp |  53 --------------
 src/fwk/toolkit/widgets/imagegridview.hpp |  42 ------------
 src/niepce/ui/dialogs/importdialog.cpp    |   5 +-
 src/niepce/ui/gridviewmodule.cpp          |   4 +-
 src/niepce/ui/gridviewmodule.hpp          |   3 +-
 src/niepce/ui/image_grid_view.rs          | 110 ++++++++++++++++++++++++++++++
 src/niepce/ui/library_cell_renderer.rs    |  13 ----
 src/niepce/ui/mod.rs                      |   1 +
 11 files changed, 123 insertions(+), 116 deletions(-)
---
diff --git a/examples/widget-test.rs b/examples/widget-test.rs
index 1f17097..8b3698d 100644
--- a/examples/widget-test.rs
+++ b/examples/widget-test.rs
@@ -28,6 +28,7 @@ use gio::{resources_register, Resource};
 use glib::{Bytes, Error};
 use gtk::prelude::*;
 
+use niepce_rust::niepce::ui::image_grid_view::ImageGridView;
 use niepce_rust::niepce::ui::thumb_nav::{ThumbNav, ThumbNavMode};
 use niepce_rust::niepce::ui::thumb_strip_view::ThumbStripView;
 use npc_fwk::toolkit::widgets::rating_label::RatingLabel;
@@ -60,7 +61,7 @@ pub fn main() {
     }
 
     let model = gtk::ListStore::new(&[gdk_pixbuf::Pixbuf::static_type()]);
-    let thumbview = ThumbStripView::new(&model.upcast::<gtk::TreeModel>());
+    let thumbview = ThumbStripView::new(model.upcast_ref::<gtk::TreeModel>());
     let thn = ThumbNav::new(
         &thumbview.upcast::<gtk::IconView>(),
         ThumbNavMode::OneRow,
@@ -70,7 +71,10 @@ pub fn main() {
 
     let box_ = gtk::Box::new(gtk::Orientation::Vertical, 0);
     let rating = RatingLabel::new(3, true);
+
+    let image_grid = ImageGridView::new(model.upcast_ref::<gtk::TreeModel>());
     box_.pack_start(&rating, false, false, 0);
+    box_.pack_start(&image_grid, true, true, 0);
     box_.pack_start(&thn, false, false, 0);
 
     let window = gtk::Window::new(gtk::WindowType::Toplevel);
diff --git a/src/Makefile.am b/src/Makefile.am
index 9c0f801..b029abd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,6 +52,7 @@ RUST_SOURCES = \
        @top_srcdir@/src/niepce/mod.rs \
        @top_srcdir@/src/niepce/ui/mod.rs \
        @top_srcdir@/src/niepce/ui/imagetoolbar.rs \
+       @top_srcdir@/src/niepce/ui/image_grid_view.rs \
        @top_srcdir@/src/niepce/ui/image_list_store.rs \
        @top_srcdir@/src/niepce/ui/dialogs/mod.rs \
        @top_srcdir@/src/niepce/ui/dialogs/confirm.rs \
diff --git a/src/fwk/toolkit/Makefile.am b/src/fwk/toolkit/Makefile.am
index 65f03d5..b7b135f 100644
--- a/src/fwk/toolkit/Makefile.am
+++ b/src/fwk/toolkit/Makefile.am
@@ -54,7 +54,6 @@ libniepceframework_a_SOURCES = configuration.hpp configuration.cpp \
        widgets/dock.cpp widgets/dock.hpp \
        widgets/notabtextview.hpp widgets/notabtextview.cpp \
        widgets/tokentextview.hpp widgets/tokentextview.cpp \
-       widgets/imagegridview.hpp widgets/imagegridview.cpp \
        dockable.hpp dockable.cpp \
        metadatawidget.hpp metadatawidget.cpp \
        undo.hpp undo.cpp \
diff --git a/src/niepce/ui/dialogs/importdialog.cpp b/src/niepce/ui/dialogs/importdialog.cpp
index 5ffbfb9..7480a50 100644
--- a/src/niepce/ui/dialogs/importdialog.cpp
+++ b/src/niepce/ui/dialogs/importdialog.cpp
@@ -33,7 +33,6 @@
 #include "fwk/utils/pathutils.hpp"
 #include "fwk/toolkit/application.hpp"
 #include "fwk/toolkit/configuration.hpp"
-#include "fwk/toolkit/widgets/imagegridview.hpp"
 #include "engine/importer/directoryimporter.hpp"
 #include "engine/importer/importedfile.hpp"
 #include "importdialog.hpp"
@@ -120,8 +119,8 @@ void ImportDialog::setup_widget()
     a_builder->get_widget("images_list_scrolled", m_images_list_scrolled);
     m_images_list_model = Gtk::ListStore::create(m_grid_columns);
     m_gridview = Gtk::manage(
-        new Gtk::IconView(
-            Glib::RefPtr<Gtk::TreeModel>::cast_dynamic(m_images_list_model)));
+        Glib::wrap(GTK_ICON_VIEW(ffi::npc_image_grid_view_new(
+                                     GTK_TREE_MODEL(g_object_ref(m_images_list_model->gobj()))))));
     m_gridview->set_pixbuf_column(m_grid_columns.pixbuf);
     m_gridview->set_text_column(m_grid_columns.filename);
     m_gridview->set_item_width(100);
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index 174a8f7..48d0731 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -117,7 +117,9 @@ Gtk::Widget * GridViewModule::buildWidget()
     return m_widget;
   }
   m_widget = &m_lib_splitview;
-  m_librarylistview = Gtk::manage(new fwk::ImageGridView(m_model->gobjmm()));
+  m_librarylistview = Gtk::manage(
+      Glib::wrap(GTK_ICON_VIEW(ffi::npc_image_grid_view_new(
+                                   GTK_TREE_MODEL(g_object_ref(m_model->gobjmm()->gobj()))))));
   m_librarylistview->set_selection_mode(Gtk::SELECTION_SINGLE);
   m_librarylistview->property_row_spacing() = 0;
   m_librarylistview->property_column_spacing() = 0;
diff --git a/src/niepce/ui/gridviewmodule.hpp b/src/niepce/ui/gridviewmodule.hpp
index 4ed48d8..756c6ec 100644
--- a/src/niepce/ui/gridviewmodule.hpp
+++ b/src/niepce/ui/gridviewmodule.hpp
@@ -26,7 +26,6 @@
 #include <gtkmm/treestore.h>
 
 #include "fwk/base/propertybag.hpp"
-#include "fwk/toolkit/widgets/imagegridview.hpp"
 #include "niepce/ui/ilibrarymodule.hpp"
 #include "niepce/ui/imoduleshell.hpp"
 #include "niepce/ui/metadatapanecontroller.hpp"
@@ -86,7 +85,7 @@ private:
   ImageListStorePtr m_model;
 
   // library split view
-  fwk::ImageGridView*          m_librarylistview;
+  Gtk::IconView* m_librarylistview;
   Gtk::ScrolledWindow          m_scrollview;
   MetaDataPaneController::Ptr  m_metapanecontroller;
   Gtk::Paned                   m_lib_splitview;
diff --git a/src/niepce/ui/image_grid_view.rs b/src/niepce/ui/image_grid_view.rs
new file mode 100644
index 0000000..8669b71
--- /dev/null
+++ b/src/niepce/ui/image_grid_view.rs
@@ -0,0 +1,110 @@
+/*
+ * niepce - niepce/ui/image_grid_view.rs
+ *
+ * Copyright (C) 2020 Hubert Figuière
+ *
+ * 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/>.
+ */
+
+use glib::subclass;
+use glib::subclass::prelude::*;
+use glib::translate::*;
+use gtk;
+use gtk::prelude::*;
+use gtk::subclass::prelude::*;
+use gtk::subclass::widget::WidgetImplExt;
+
+use super::library_cell_renderer::LibraryCellRenderer;
+use npc_fwk::toolkit::clickable_cell_renderer::ClickableCellRenderer;
+
+glib_wrapper! {
+    pub struct ImageGridView(
+        Object<subclass::simple::InstanceStruct<ImageGridViewPriv>,
+        subclass::simple::ClassStruct<ImageGridViewPriv>,
+        ImageGridViewClass>)
+        @extends gtk::Widget, gtk::Container, gtk::IconView;
+
+    match fn {
+        get_type => || ImageGridViewPriv::get_type().to_glib(),
+    }
+}
+
+impl ImageGridView {
+    pub fn new(store: &gtk::TreeModel) -> Self {
+        glib::Object::new(Self::static_type(), &[("model", store)])
+            .expect("Failed to create ImageGridView")
+            .downcast()
+            .expect("Created ImageGridView is of the wrong type")
+    }
+}
+
+pub struct ImageGridViewPriv {}
+
+static PROPERTIES: [subclass::Property; 0] = [];
+
+impl ObjectSubclass for ImageGridViewPriv {
+    const NAME: &'static str = "ImageGridView";
+    type ParentType = gtk::IconView;
+    type Instance = subclass::simple::InstanceStruct<Self>;
+    type Class = subclass::simple::ClassStruct<Self>;
+
+    glib_object_subclass!();
+
+    fn class_init(klass: &mut Self::Class) {
+        klass.install_properties(&PROPERTIES);
+    }
+
+    fn new() -> Self {
+        Self {}
+    }
+}
+
+impl ObjectImpl for ImageGridViewPriv {
+    glib_object_impl!();
+
+    fn constructed(&self, obj: &glib::Object) {
+        self.parent_constructed(obj);
+    }
+}
+
+impl WidgetImpl for ImageGridViewPriv {
+    fn button_press_event(&self, widget: &gtk::Widget, event: &gdk::EventButton) -> gtk::Inhibit {
+        let r = self.parent_button_press_event(widget, event);
+
+        if let Some((x, y)) = event.get_coords() {
+            if let Some(iconview) = widget.downcast_ref::<gtk::IconView>() {
+                if let Some((_, cell)) = iconview.get_item_at_pos(x as i32, y as i32) {
+                    if let Ok(mut cell) = cell.downcast::<LibraryCellRenderer>() {
+                        cell.hit(x as i32, y as i32);
+                    }
+                }
+            }
+        }
+
+        r
+    }
+}
+
+impl ContainerImpl for ImageGridViewPriv {}
+
+impl IconViewImpl for ImageGridViewPriv {}
+
+#[no_mangle]
+pub unsafe extern "C" fn npc_image_grid_view_new(
+    store: *mut gtk_sys::GtkTreeModel,
+) -> *mut gtk_sys::GtkWidget {
+    ImageGridView::new(&gtk::TreeModel::from_glib_full(store))
+        .upcast::<gtk::Widget>()
+        .to_glib_full()
+}
diff --git a/src/niepce/ui/library_cell_renderer.rs b/src/niepce/ui/library_cell_renderer.rs
index 909b702..7884c82 100644
--- a/src/niepce/ui/library_cell_renderer.rs
+++ b/src/niepce/ui/library_cell_renderer.rs
@@ -633,16 +633,3 @@ pub unsafe extern "C" fn npc_library_cell_renderer_new(
         .upcast::<gtk::CellRenderer>()
         .to_glib_full()
 }
-
-/// Hit test for the cellrenderer.
-#[no_mangle]
-pub unsafe extern "C" fn npc_library_cell_renderer_hit(
-    ptr: *mut gtk_sys::GtkCellRenderer,
-    x: i32,
-    y: i32,
-) {
-    let mut renderer = gtk::CellRenderer::from_glib_borrow(ptr)
-        .downcast::<LibraryCellRenderer>()
-        .expect("Expected a LibraryCellRenderer");
-    renderer.hit(x, y);
-}
diff --git a/src/niepce/ui/mod.rs b/src/niepce/ui/mod.rs
index d40ecdc..4777133 100644
--- a/src/niepce/ui/mod.rs
+++ b/src/niepce/ui/mod.rs
@@ -18,6 +18,7 @@
  */
 
 pub mod dialogs;
+pub mod image_grid_view;
 pub mod image_list_store;
 pub mod imagetoolbar;
 pub mod library_cell_renderer;


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