[gnome-photos] Port the Dropdown widget to GtkPopover
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Port the Dropdown widget to GtkPopover
- Date: Tue, 10 Mar 2015 08:45:53 +0000 (UTC)
commit ad0bab7c194f21b09b4d711a0aa2d9e3a68997b2
Author: Alessandro Bono <shadow openaliasbox org>
Date: Sat Mar 7 02:19:03 2015 +0100
Port the Dropdown widget to GtkPopover
GtkPopover allows hiding interface elements out of the way. The
problem of click handling for dropdown menu is solved by using
GtkPopover.
https://bugzilla.gnome.org/show_bug.cgi?id=726462
src/photos-base-view.c | 22 -----------
src/photos-base-view.h | 3 --
src/photos-dropdown.c | 71 +++++++------------------------------
src/photos-dropdown.h | 9 ++---
src/photos-main-toolbar.c | 9 +----
src/photos-overview-searchbar.c | 75 ++++++++-------------------------------
src/photos-overview-searchbar.h | 2 +-
7 files changed, 33 insertions(+), 158 deletions(-)
---
diff --git a/src/photos-base-view.c b/src/photos-base-view.c
index 4c1637b..d826f46 100644
--- a/src/photos-base-view.c
+++ b/src/photos-base-view.c
@@ -45,14 +45,6 @@ enum
PROP_MANAGER
};
-enum
-{
- ITEM_ACTIVATED,
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = { 0 };
-
G_DEFINE_TYPE_WITH_PRIVATE (PhotosBaseView, photos_base_view, GTK_TYPE_TREE_VIEW);
@@ -155,10 +147,7 @@ photos_base_view_row_activated (GtkTreeView *tree_view, GtkTreePath *path, GtkTr
gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->model), &iter, path);
gtk_tree_model_get (GTK_TREE_MODEL (priv->model), &iter, PHOTOS_BASE_MODEL_ID, &id, -1);
-
- g_signal_emit (self, signals[ITEM_ACTIVATED], 0);
photos_base_manager_set_active_object_by_id (priv->mngr, id);
-
g_free (id);
}
@@ -271,17 +260,6 @@ photos_base_view_class_init (PhotosBaseViewClass *class)
"The manager whose data is being rendered by this
view",
PHOTOS_TYPE_BASE_MANAGER,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
-
- signals[ITEM_ACTIVATED] = g_signal_new ("item-activated",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (PhotosBaseViewClass,
- item_activated),
- NULL, /*accumulator */
- NULL, /*accu_data */
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
}
diff --git a/src/photos-base-view.h b/src/photos-base-view.h
index 44c9e0f..a9b5e92 100644
--- a/src/photos-base-view.h
+++ b/src/photos-base-view.h
@@ -66,9 +66,6 @@ struct _PhotosBaseView
struct _PhotosBaseViewClass
{
GtkTreeViewClass parent_class;
-
- /* signals */
- void (*item_activated) (PhotosBaseView *self);
};
GType photos_base_view_get_type (void) G_GNUC_CONST;
diff --git a/src/photos-dropdown.c b/src/photos-dropdown.c
index 92735eb..b45326c 100644
--- a/src/photos-dropdown.c
+++ b/src/photos-dropdown.c
@@ -43,23 +43,8 @@ struct _PhotosDropdownPrivate
PhotosBaseManager *src_mngr;
};
-enum
-{
- ITEM_ACTIVATED,
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE_WITH_PRIVATE (PhotosDropdown, photos_dropdown, GTK_TYPE_REVEALER);
-
-
-static void
-photos_dropdown_item_activated (PhotosDropdown *self)
-{
- g_signal_emit (self, signals[ITEM_ACTIVATED], 0);
-}
+G_DEFINE_TYPE_WITH_PRIVATE (PhotosDropdown, photos_dropdown, GTK_TYPE_POPOVER);
static void
@@ -82,7 +67,6 @@ photos_dropdown_init (PhotosDropdown *self)
PhotosDropdownPrivate *priv;
GApplication *app;
GtkStyleContext *context;
- GtkWidget *frame;
PhotosSearchContextState *state;
self->priv = photos_dropdown_get_instance_private (self);
@@ -99,27 +83,23 @@ photos_dropdown_init (PhotosDropdown *self)
priv->source_view = photos_base_view_new (priv->src_mngr);
priv->type_view = photos_base_view_new (priv->srch_typ_mngr);
- g_signal_connect_swapped (priv->match_view, "item-activated", G_CALLBACK (photos_dropdown_item_activated),
self);
- g_signal_connect_swapped (priv->source_view, "item-activated", G_CALLBACK
(photos_dropdown_item_activated), self);
- g_signal_connect_swapped (priv->type_view, "item-activated", G_CALLBACK (photos_dropdown_item_activated),
self);
-
- frame = gtk_frame_new (NULL);
- gtk_widget_set_opacity (frame, 0.9);
- gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
- context = gtk_widget_get_style_context (frame);
- gtk_style_context_add_class (context, "photos-dropdown");
- gtk_container_add (GTK_CONTAINER (self), frame);
-
priv->grid = gtk_grid_new ();
+ gtk_widget_set_margin_start (priv->grid, 10);
+ gtk_widget_set_margin_end (priv->grid, 10);
+ gtk_widget_set_margin_bottom (priv->grid, 10);
+ gtk_widget_set_margin_top (priv->grid, 10);
gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->grid), GTK_ORIENTATION_HORIZONTAL);
- gtk_container_add (GTK_CONTAINER (frame), priv->grid);
+ gtk_grid_set_row_homogeneous (GTK_GRID (priv->grid), TRUE);
+ gtk_container_add (GTK_CONTAINER (self), priv->grid);
gtk_container_add (GTK_CONTAINER (priv->grid), priv->source_view);
gtk_container_add (GTK_CONTAINER (priv->grid), priv->type_view);
gtk_container_add (GTK_CONTAINER (priv->grid), priv->match_view);
- photos_dropdown_hide (self);
- gtk_widget_show_all (GTK_WIDGET (self));
+ context = gtk_widget_get_style_context (GTK_WIDGET (self));
+ gtk_style_context_add_class (context, "photos-dropdown");
+ gtk_widget_hide (GTK_WIDGET(self));
+ gtk_widget_show_all (GTK_WIDGET (priv->grid));
}
@@ -129,36 +109,11 @@ photos_dropdown_class_init (PhotosDropdownClass *class)
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->dispose = photos_dropdown_dispose;
-
- signals[ITEM_ACTIVATED] = g_signal_new ("item-activated",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (PhotosDropdownClass,
- item_activated),
- NULL, /*accumulator */
- NULL, /*accu_data */
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
}
GtkWidget *
-photos_dropdown_new (void)
-{
- return g_object_new (PHOTOS_TYPE_DROPDOWN, "halign", GTK_ALIGN_CENTER, "valign", GTK_ALIGN_START, NULL);
-}
-
-
-void
-photos_dropdown_hide (PhotosDropdown *self)
-{
- gtk_revealer_set_reveal_child (GTK_REVEALER (self), FALSE);
-}
-
-
-void
-photos_dropdown_show (PhotosDropdown *self)
+photos_dropdown_new (GtkWidget *relative_to)
{
- gtk_revealer_set_reveal_child (GTK_REVEALER (self), TRUE);
+ return g_object_new (PHOTOS_TYPE_DROPDOWN, "relative-to", relative_to, "height_request", 240, NULL);
}
diff --git a/src/photos-dropdown.h b/src/photos-dropdown.h
index 2717aba..60ea4c1 100644
--- a/src/photos-dropdown.h
+++ b/src/photos-dropdown.h
@@ -57,21 +57,18 @@ typedef struct _PhotosDropdownPrivate PhotosDropdownPrivate;
struct _PhotosDropdown
{
- GtkRevealer parent_instance;
+ GtkPopover parent_instance;
PhotosDropdownPrivate *priv;
};
struct _PhotosDropdownClass
{
- GtkRevealerClass parent_class;
-
- /* signals */
- void (*item_activated) (PhotosDropdown *self);
+ GtkPopoverClass parent_class;
};
GType photos_dropdown_get_type (void) G_GNUC_CONST;
-GtkWidget *photos_dropdown_new (void);
+GtkWidget *photos_dropdown_new (GtkWidget *relative_to);
void photos_dropdown_hide (PhotosDropdown *self);
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index 3d41c4c..2e93736 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -391,14 +391,7 @@ photos_main_toolbar_clear_toolbar (PhotosMainToolbar *self)
static GtkWidget *
photos_main_toolbar_create_overview_searchbar (PhotosMainToolbar *self)
{
- GtkWidget *dropdown;
- GtkWidget *searchbar;
-
- dropdown = photos_dropdown_new ();
- gtk_overlay_add_overlay (GTK_OVERLAY (self->priv->overlay), dropdown);
- searchbar = photos_overview_searchbar_new (PHOTOS_DROPDOWN (dropdown));
-
- return searchbar;
+ return photos_overview_searchbar_new ();
}
diff --git a/src/photos-overview-searchbar.c b/src/photos-overview-searchbar.c
index a9c915e..1a2ccb6 100644
--- a/src/photos-overview-searchbar.c
+++ b/src/photos-overview-searchbar.c
@@ -29,6 +29,7 @@
#include <libgd/gd.h>
#include "photos-base-manager.h"
+#include "photos-dropdown.h"
#include "photos-filterable.h"
#include "photos-icons.h"
#include "photos-overview-searchbar.h"
@@ -54,12 +55,6 @@ struct _PhotosOverviewSearchbarPrivate
PhotosSearchController *srch_cntrlr;
};
-enum
-{
- PROP_0,
- PROP_DROPDOWN
-};
-
G_DEFINE_TYPE_WITH_PRIVATE (PhotosOverviewSearchbar, photos_overview_searchbar, PHOTOS_TYPE_SEARCHBAR);
@@ -116,6 +111,13 @@ photos_overview_searchbar_collection_active_changed (PhotosOverviewSearchbar *se
static void
+photos_overview_searchbar_closed (PhotosOverviewSearchbar *self)
+{
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->dropdown_button), FALSE);
+}
+
+
+static void
photos_overview_searchbar_hide (PhotosSearchbar *searchbar)
{
PhotosOverviewSearchbar *self = PHOTOS_OVERVIEW_SEARCHBAR (searchbar);
@@ -133,13 +135,6 @@ photos_overview_searchbar_hide (PhotosSearchbar *searchbar)
static void
-photos_overview_searchbar_item_activated (PhotosOverviewSearchbar *self)
-{
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->dropdown_button), FALSE);
-}
-
-
-static void
photos_overview_searchbar_search_match_active_changed (PhotosOverviewSearchbar *self)
{
PhotosOverviewSearchbarPrivate *priv = self->priv;
@@ -210,10 +205,9 @@ static void
photos_overview_searchbar_toggled (PhotosOverviewSearchbar *self)
{
PhotosOverviewSearchbarPrivate *priv = self->priv;
- gboolean active;
- active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->dropdown_button));
- gtk_revealer_set_reveal_child (GTK_REVEALER (priv->dropdown), active);
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->dropdown_button)))
+ gtk_widget_show (GTK_WIDGET(priv->dropdown));
}
@@ -254,9 +248,10 @@ photos_overview_searchbar_create_search_widgets (PhotosSearchbar *searchbar)
gtk_style_context_add_class (context, "raised");
g_signal_connect_swapped (priv->dropdown_button, "toggled", G_CALLBACK
(photos_overview_searchbar_toggled), self);
+ priv->dropdown = photos_dropdown_new (GTK_WIDGET (priv->dropdown_button));
g_signal_connect_swapped (priv->dropdown,
- "item-activated",
- G_CALLBACK (photos_overview_searchbar_item_activated),
+ "closed",
+ G_CALLBACK (photos_overview_searchbar_closed),
self);
priv->search_container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
@@ -286,17 +281,6 @@ photos_overview_searchbar_entry_changed (PhotosSearchbar *searchbar)
static void
-photos_overview_searchbar_destroy (GtkWidget *widget)
-{
- PhotosOverviewSearchbar *self = PHOTOS_OVERVIEW_SEARCHBAR (widget);
-
- gtk_revealer_set_reveal_child (GTK_REVEALER (self->priv->dropdown), FALSE);
-
- GTK_WIDGET_CLASS (photos_overview_searchbar_parent_class)->destroy (widget);
-}
-
-
-static void
photos_overview_searchbar_constructed (GObject *object)
{
PhotosOverviewSearchbar *self = PHOTOS_OVERVIEW_SEARCHBAR (object);
@@ -326,24 +310,6 @@ photos_overview_searchbar_dispose (GObject *object)
static void
-photos_overview_searchbar_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec
*pspec)
-{
- PhotosOverviewSearchbar *self = PHOTOS_OVERVIEW_SEARCHBAR (object);
-
- switch (prop_id)
- {
- case PROP_DROPDOWN:
- self->priv->dropdown = GTK_WIDGET (g_value_dup_object (value));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-
-static void
photos_overview_searchbar_init (PhotosOverviewSearchbar *self)
{
PhotosOverviewSearchbarPrivate *priv;
@@ -394,30 +360,19 @@ static void
photos_overview_searchbar_class_init (PhotosOverviewSearchbarClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
PhotosSearchbarClass *searchbar_class = PHOTOS_SEARCHBAR_CLASS (class);
object_class->constructed = photos_overview_searchbar_constructed;
object_class->dispose = photos_overview_searchbar_dispose;
- object_class->set_property = photos_overview_searchbar_set_property;
- widget_class->destroy = photos_overview_searchbar_destroy;
searchbar_class->create_search_widgets = photos_overview_searchbar_create_search_widgets;
searchbar_class->entry_changed = photos_overview_searchbar_entry_changed;
searchbar_class->hide = photos_overview_searchbar_hide;
searchbar_class->show = photos_overview_searchbar_show;
-
- g_object_class_install_property (object_class,
- PROP_DROPDOWN,
- g_param_spec_object ("dropdown",
- "PhotosDropdown object",
- "The dropdown widget for this searchbar",
- PHOTOS_TYPE_DROPDOWN,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
}
GtkWidget *
-photos_overview_searchbar_new (PhotosDropdown *dropdown)
+photos_overview_searchbar_new (void)
{
- return g_object_new (PHOTOS_TYPE_OVERVIEW_SEARCHBAR, "dropdown", dropdown, NULL);
+ return g_object_new (PHOTOS_TYPE_OVERVIEW_SEARCHBAR, NULL);
}
diff --git a/src/photos-overview-searchbar.h b/src/photos-overview-searchbar.h
index 35a3ef8..a44ae3f 100644
--- a/src/photos-overview-searchbar.h
+++ b/src/photos-overview-searchbar.h
@@ -69,7 +69,7 @@ struct _PhotosOverviewSearchbarClass
GType photos_overview_searchbar_get_type (void) G_GNUC_CONST;
-GtkWidget *photos_overview_searchbar_new (PhotosDropdown *dropdown);
+GtkWidget *photos_overview_searchbar_new (void);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]