From 4d314b612c11d125dbcbf4b982951ed91baaf09d Mon Sep 17 00:00:00 2001 From: raveit65 Date: Sun, 14 Jun 2015 17:18:17 +0200 Subject: EomThumbView: Implement GtkOrientable --- src/eom-thumb-view.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src') diff --git a/src/eom-thumb-view.c b/src/eom-thumb-view.c index e52886c..1a8f4f1 100644 --- a/src/eom-thumb-view.c +++ b/src/eom-thumb-view.c @@ -38,12 +38,23 @@ #include #include +#if GTK_CHECK_VERSION (3, 4, 3) +enum { + PROP_0, + PROP_ORIENTATION +}; +#endif + #define EOM_THUMB_VIEW_SPACING 0 #define EOM_THUMB_VIEW_GET_PRIVATE(object) \ (G_TYPE_INSTANCE_GET_PRIVATE ((object), EOM_TYPE_THUMB_VIEW, EomThumbViewPrivate)) +#if GTK_CHECK_VERSION (3, 4, 3) +static void eom_thumb_view_init (EomThumbView *thumbview); +#else G_DEFINE_TYPE (EomThumbView, eom_thumb_view, GTK_TYPE_ICON_VIEW); +#endif static EomImage* eom_thumb_view_get_image_from_path (EomThumbView *thumbview, GtkTreePath *path); @@ -51,6 +62,11 @@ static EomImage* eom_thumb_view_get_image_from_path (EomThumbView *thumbvie static void eom_thumb_view_popup_menu (EomThumbView *widget, GdkEventButton *event); +#if GTK_CHECK_VERSION (3, 4, 3) +G_DEFINE_TYPE_WITH_CODE (EomThumbView, eom_thumb_view, GTK_TYPE_ICON_VIEW, + G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)); +#endif + static gboolean thumbview_on_query_tooltip_cb (GtkWidget *widget, gint x, @@ -81,6 +97,10 @@ struct _EomThumbViewPrivate { GtkWidget *menu; /* a contextual menu for thumbnails */ GtkCellRenderer *pixbuf_cell; gint visible_range_changed_id; + +#if GTK_CHECK_VERSION (3, 4, 3) + GtkOrientation orientation; +#endif }; /* Drag 'n Drop */ @@ -189,6 +209,47 @@ eom_thumb_view_destroy (GtkObject *object) #endif } +#if GTK_CHECK_VERSION (3, 4, 3) +static void +eom_thumb_view_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EomThumbView *view = EOM_THUMB_VIEW (object); + + switch (prop_id) + { + case PROP_ORIENTATION: + g_value_set_enum (value, view->priv->orientation); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +eom_thumb_view_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EomThumbView *view = EOM_THUMB_VIEW (object); + + switch (prop_id) + { + case PROP_ORIENTATION: + view->priv->orientation = g_value_get_enum (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} +#endif + static void eom_thumb_view_class_init (EomThumbViewClass *class) { @@ -200,6 +261,13 @@ eom_thumb_view_class_init (EomThumbViewClass *class) #endif gobject_class->constructed = eom_thumb_view_constructed; gobject_class->dispose = eom_thumb_view_dispose; +#if GTK_CHECK_VERSION (3, 4, 3) + gobject_class->get_property = eom_thumb_view_get_property; + gobject_class->set_property = eom_thumb_view_set_property; + + g_object_class_override_property (gobject_class, PROP_ORIENTATION, + "orientation"); +#endif gobject_class->finalize = eom_thumb_view_finalize; #if GTK_CHECK_VERSION(3, 0, 0) widget_class->destroy = eom_thumb_view_destroy; -- cgit v1.2.1 From 16ecee965b67eaf37e52c745f6369f49377e86b2 Mon Sep 17 00:00:00 2001 From: raveit65 Date: Sun, 14 Jun 2015 17:58:12 +0200 Subject: EogThumbView: Set icon view columns to the real number of images GtkIconView's layout code was redone in gtk+-3.4.3 and 3.4.4 breaking EogThumbView which would scale the thumbnails so small that the thumbview would not be shown itself in single row mode. This should work with gtk+-3.4.2 and earlier as well. taken from: https://git.gnome.org/browse/eog/commit/?id=888b5ed --- src/eom-thumb-nav.c | 20 ++++++++++ src/eom-thumb-view.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) (limited to 'src') diff --git a/src/eom-thumb-nav.c b/src/eom-thumb-nav.c index 702b4c5..24c2431 100644 --- a/src/eom-thumb-nav.c +++ b/src/eom-thumb-nav.c @@ -545,8 +545,13 @@ eom_thumb_nav_set_mode (EomThumbNav *nav, EomThumbNavMode mode) switch (mode) { case EOM_THUMB_NAV_MODE_ONE_ROW: +#if GTK_CHECK_VERSION (3, 4, 3) + gtk_orientable_set_orientation (GTK_ORIENTABLE(priv->thumbview), + GTK_ORIENTATION_HORIZONTAL); +#else gtk_icon_view_set_columns (GTK_ICON_VIEW (priv->thumbview), G_MAXINT); +#endif gtk_widget_set_size_request (priv->thumbview, -1, -1); eom_thumb_view_set_item_height (EOM_THUMB_VIEW (priv->thumbview), @@ -561,7 +566,12 @@ eom_thumb_nav_set_mode (EomThumbNav *nav, EomThumbNavMode mode) break; case EOM_THUMB_NAV_MODE_ONE_COLUMN: +#if GTK_CHECK_VERSION (3, 4, 3) + gtk_orientable_set_orientation (GTK_ORIENTABLE(priv->thumbview), + GTK_ORIENTATION_VERTICAL); +#else gtk_icon_view_set_columns (GTK_ICON_VIEW (priv->thumbview), 1); +#endif gtk_widget_set_size_request (priv->thumbview, -1, -1); eom_thumb_view_set_item_height (EOM_THUMB_VIEW (priv->thumbview), @@ -577,7 +587,12 @@ eom_thumb_nav_set_mode (EomThumbNav *nav, EomThumbNavMode mode) break; case EOM_THUMB_NAV_MODE_MULTIPLE_ROWS: +#if GTK_CHECK_VERSION (3, 4, 3) + gtk_orientable_set_orientation (GTK_ORIENTABLE(priv->thumbview), + GTK_ORIENTATION_VERTICAL); +#else gtk_icon_view_set_columns (GTK_ICON_VIEW (priv->thumbview), -1); +#endif gtk_widget_set_size_request (priv->thumbview, -1, 220); eom_thumb_view_set_item_height (EOM_THUMB_VIEW (priv->thumbview), @@ -593,7 +608,12 @@ eom_thumb_nav_set_mode (EomThumbNav *nav, EomThumbNavMode mode) break; case EOM_THUMB_NAV_MODE_MULTIPLE_COLUMNS: +#if GTK_CHECK_VERSION (3, 4, 3) + gtk_orientable_set_orientation (GTK_ORIENTABLE(priv->thumbview), + GTK_ORIENTATION_VERTICAL); +#else gtk_icon_view_set_columns (GTK_ICON_VIEW (priv->thumbview), -1); +#endif gtk_widget_set_size_request (priv->thumbview, 230, -1); eom_thumb_view_set_item_height (EOM_THUMB_VIEW (priv->thumbview), diff --git a/src/eom-thumb-view.c b/src/eom-thumb-view.c index 1a8f4f1..aba4eba 100644 --- a/src/eom-thumb-view.c +++ b/src/eom-thumb-view.c @@ -63,6 +63,8 @@ static void eom_thumb_view_popup_menu (EomThumbView *widget, GdkEventButton *event); #if GTK_CHECK_VERSION (3, 4, 3) +static void eom_thumb_view_update_columns (EomThumbView *view); + G_DEFINE_TYPE_WITH_CODE (EomThumbView, eom_thumb_view, GTK_TYPE_ICON_VIEW, G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)); #endif @@ -100,6 +102,9 @@ struct _EomThumbViewPrivate { #if GTK_CHECK_VERSION (3, 4, 3) GtkOrientation orientation; + gint n_images; + gulong image_add_id; + gulong image_removed_id; #endif }; @@ -172,12 +177,29 @@ static void eom_thumb_view_dispose (GObject *object) { EomThumbViewPrivate *priv = EOM_THUMB_VIEW (object)->priv; +#if GTK_CHECK_VERSION (3, 4, 3) + GtkTreeModel *model; +#endif if (priv->visible_range_changed_id != 0) { g_source_remove (priv->visible_range_changed_id); priv->visible_range_changed_id = 0; } +#if GTK_CHECK_VERSION (3, 4, 3) + model = gtk_icon_view_get_model (GTK_ICON_VIEW (object)); + + if (model && priv->image_add_id != 0) { + g_signal_handler_disconnect (model, priv->image_add_id); + priv->image_add_id = 0; + } + + if (model && priv->image_removed_id) { + g_signal_handler_disconnect (model, priv->image_removed_id); + priv->image_removed_id = 0; + } +#endif + G_OBJECT_CLASS (eom_thumb_view_parent_class)->dispose (object); } @@ -242,6 +264,9 @@ eom_thumb_view_set_property (GObject *object, { case PROP_ORIENTATION: view->priv->orientation = g_value_get_enum (value); +#if GTK_CHECK_VERSION (3, 4, 3) + eom_thumb_view_update_columns (view); +#endif break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -684,6 +709,10 @@ eom_thumb_view_init (EomThumbView *thumbview) thumbview->priv = EOM_THUMB_VIEW_GET_PRIVATE (thumbview); thumbview->priv->visible_range_changed_id = 0; +#if GTK_CHECK_VERSION (3, 4, 3) + thumbview->priv->image_add_id = 0; + thumbview->priv->image_removed_id = 0; +#endif } /** @@ -703,6 +732,45 @@ eom_thumb_view_new (void) return GTK_WIDGET (thumbview); } +#if GTK_CHECK_VERSION (3, 4, 3) +static void +eom_thumb_view_update_columns (EomThumbView *view) +{ + EomThumbViewPrivate *priv; + + g_return_if_fail (EOM_IS_THUMB_VIEW (view)); + + priv = view->priv; + + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + gtk_icon_view_set_columns (GTK_ICON_VIEW (view), + priv->n_images); +} + +static void +eom_thumb_view_row_inserted_cb (GtkTreeModel *tree_model, + GtkTreePath *path, + GtkTreeIter *iter, + EomThumbView *view) +{ + EomThumbViewPrivate *priv = view->priv; + + priv->n_images++; + eom_thumb_view_update_columns (view); +} + +static void +eom_thumb_view_row_deleted_cb (GtkTreeModel *tree_model, + GtkTreePath *path, + EomThumbView *view) +{ + EomThumbViewPrivate *priv = view->priv; + + priv->n_images--; + eom_thumb_view_update_columns (view); +} +#endif + /** * eom_thumb_view_set_model: * @thumbview: A #EomThumbView. @@ -716,13 +784,52 @@ void eom_thumb_view_set_model (EomThumbView *thumbview, EomListStore *store) { gint index; +#if GTK_CHECK_VERSION (3, 4, 3) + EomThumbViewPrivate *priv; + GtkTreeModel *existing; +#endif g_return_if_fail (EOM_IS_THUMB_VIEW (thumbview)); g_return_if_fail (EOM_IS_LIST_STORE (store)); +#if GTK_CHECK_VERSION (3, 4, 3) + priv = thumbview->priv; + + existing = gtk_icon_view_get_model (GTK_ICON_VIEW (thumbview)); + + if (existing != NULL) { + if (priv->image_add_id != 0) { + g_signal_handler_disconnect (existing, + priv->image_add_id); + } + if (priv->image_removed_id != 0) { + g_signal_handler_disconnect (existing, + priv->image_removed_id); + + } + } + + priv->image_add_id = g_signal_connect (G_OBJECT (store), "row-inserted", + G_CALLBACK (eom_thumb_view_row_inserted_cb), + thumbview); + priv->image_removed_id = g_signal_connect (G_OBJECT (store), + "row-deleted", + G_CALLBACK (eom_thumb_view_row_deleted_cb), + thumbview); + + thumbview->priv->n_images = eom_list_store_length (store); +#endif + index = eom_list_store_get_initial_pos (store); +#if GTK_CHECK_VERSION (3, 4, 3) + gtk_icon_view_set_model (GTK_ICON_VIEW (thumbview), + GTK_TREE_MODEL (store)); + + eom_thumb_view_update_columns (thumbview); +#else gtk_icon_view_set_model (GTK_ICON_VIEW (thumbview), GTK_TREE_MODEL (store)); +#endif if (index >= 0) { GtkTreePath *path = gtk_tree_path_new_from_indices (index, -1); -- cgit v1.2.1