diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2009-08-27 11:46:56 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2009-08-28 05:35:21 +0800 |
commit | 0e1066b431b3d172c18b7be8744875942515e117 (patch) | |
tree | 3f57d52c48f98379fe41dc5879d2da2bc6e58995 | |
parent | e1efca844727d9dc06b9d721be8434c1ffaf3fa7 (diff) | |
download | gsoc2013-evolution-0e1066b431b3d172c18b7be8744875942515e117.tar gsoc2013-evolution-0e1066b431b3d172c18b7be8744875942515e117.tar.gz gsoc2013-evolution-0e1066b431b3d172c18b7be8744875942515e117.tar.bz2 gsoc2013-evolution-0e1066b431b3d172c18b7be8744875942515e117.tar.lz gsoc2013-evolution-0e1066b431b3d172c18b7be8744875942515e117.tar.xz gsoc2013-evolution-0e1066b431b3d172c18b7be8744875942515e117.tar.zst gsoc2013-evolution-0e1066b431b3d172c18b7be8744875942515e117.zip |
Add EPaned widget to generalize vertical view.
-rw-r--r-- | modules/mail/e-mail-shell-content.c | 160 | ||||
-rw-r--r-- | modules/mail/e-mail-shell-content.h | 5 | ||||
-rw-r--r-- | widgets/misc/Makefile.am | 2 | ||||
-rw-r--r-- | widgets/misc/e-paned.c | 344 | ||||
-rw-r--r-- | widgets/misc/e-paned.h | 75 |
5 files changed, 441 insertions, 145 deletions
diff --git a/modules/mail/e-mail-shell-content.c b/modules/mail/e-mail-shell-content.c index faa74473ac..9bea68f9cb 100644 --- a/modules/mail/e-mail-shell-content.c +++ b/modules/mail/e-mail-shell-content.c @@ -25,9 +25,11 @@ #include <camel/camel-store.h> #include <libedataserver/e-data-server-util.h> +#include "e-util/e-binding.h" #include "e-util/gconf-bridge.h" #include "widgets/menus/gal-view-etable.h" #include "widgets/menus/gal-view-instance.h" +#include "widgets/misc/e-paned.h" #include "em-search-context.h" #include "em-utils.h" @@ -72,7 +74,6 @@ struct _EMailShellContentPrivate { enum { PROP_0, - PROP_PREVIEW_SIZE, PROP_PREVIEW_VISIBLE, PROP_SHOW_DELETED, PROP_VERTICAL_VIEW @@ -82,12 +83,6 @@ static gpointer parent_class; static GType mail_shell_content_type; static void -mail_shell_content_notify_preview_size (EMailShellContent *mail_shell_content) -{ - g_object_notify (G_OBJECT (mail_shell_content), "preview-size"); -} - -static void mail_shell_content_etree_unfreeze (MessageList *message_list, GdkEvent *event) { @@ -323,12 +318,6 @@ mail_shell_content_set_property (GObject *object, GParamSpec *pspec) { switch (property_id) { - case PROP_PREVIEW_SIZE: - e_mail_shell_content_set_preview_size ( - E_MAIL_SHELL_CONTENT (object), - g_value_get_int (value)); - return; - case PROP_PREVIEW_VISIBLE: e_mail_shell_content_set_preview_visible ( E_MAIL_SHELL_CONTENT (object), @@ -358,13 +347,6 @@ mail_shell_content_get_property (GObject *object, GParamSpec *pspec) { switch (property_id) { - case PROP_PREVIEW_SIZE: - g_value_set_int ( - value, - e_mail_shell_content_get_preview_size ( - E_MAIL_SHELL_CONTENT (object))); - return; - case PROP_PREVIEW_VISIBLE: g_value_set_boolean ( value, @@ -384,6 +366,7 @@ mail_shell_content_get_property (GObject *object, value, e_mail_shell_content_get_vertical_view ( E_MAIL_SHELL_CONTENT (object))); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -460,15 +443,14 @@ mail_shell_content_constructed (GObject *object) container = GTK_WIDGET (object); - widget = gtk_vpaned_new (); + widget = e_paned_new (GTK_ORIENTATION_VERTICAL); gtk_container_add (GTK_CONTAINER (container), widget); priv->paned = g_object_ref (widget); gtk_widget_show (widget); - g_signal_connect_swapped ( - widget, "notify::position", - G_CALLBACK (mail_shell_content_notify_preview_size), - shell_content); + e_binding_new ( + G_OBJECT (object), "vertical-view", + G_OBJECT (widget), "vertical-view"); container = widget; @@ -512,6 +494,14 @@ mail_shell_content_constructed (GObject *object) bridge = gconf_bridge_get (); + object = G_OBJECT (priv->paned); + key = "/apps/evolution/mail/display/hpaned_size"; + gconf_bridge_bind_property (bridge, key, object, "hposition"); + + object = G_OBJECT (priv->paned); + key = "/apps/evolution/mail/display/paned_size"; + gconf_bridge_bind_property (bridge, key, object, "vposition"); + object = G_OBJECT (shell_content); key = "/apps/evolution/mail/display/show_deleted"; gconf_bridge_bind_property (bridge, key, object, "show-deleted"); @@ -527,33 +517,6 @@ mail_shell_content_constructed (GObject *object) shell_content); } -static void -mail_shell_content_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - EMailShellContentPrivate *priv; - GConfBridge *bridge; - const gchar *key; - - priv = E_MAIL_SHELL_CONTENT_GET_PRIVATE (widget); - - /* Chain up to parent's size_allocate() method. */ - GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation); - - if (priv->paned_binding_id > 0) - return; - - bridge = gconf_bridge_get (); - - if (priv->vertical_view) - key = "/apps/evolution/mail/display/hpaned_size"; - else - key = "/apps/evolution/mail/display/paned_size"; - - priv->paned_binding_id = gconf_bridge_bind_property_delayed ( - bridge, key, G_OBJECT (widget), "preview-size"); -} - static guint32 mail_shell_content_check_state (EShellContent *shell_content) { @@ -690,7 +653,6 @@ static void mail_shell_content_class_init (EMailShellContentClass *class) { GObjectClass *object_class; - GtkWidgetClass *widget_class; EShellContentClass *shell_content_class; parent_class = g_type_class_peek_parent (class); @@ -702,27 +664,12 @@ mail_shell_content_class_init (EMailShellContentClass *class) object_class->dispose = mail_shell_content_dispose; object_class->constructed = mail_shell_content_constructed; - widget_class = GTK_WIDGET_CLASS (class); - widget_class->size_allocate = mail_shell_content_size_allocate; - shell_content_class = E_SHELL_CONTENT_CLASS (class); shell_content_class->new_search_context = em_search_context_new; shell_content_class->check_state = mail_shell_content_check_state; g_object_class_install_property ( object_class, - PROP_PREVIEW_SIZE, - g_param_spec_int ( - "preview-size", - _("Preview Size"), - _("Size of the preview pane in pixels"), - G_MININT, - G_MAXINT, - 100, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, PROP_PREVIEW_VISIBLE, g_param_spec_boolean ( "preview-visible", @@ -823,53 +770,6 @@ e_mail_shell_content_new (EShellView *shell_view) "shell-view", shell_view, NULL); } -gint -e_mail_shell_content_get_preview_size (EMailShellContent *mail_shell_content) -{ - GtkOrientable *orientable; - GtkOrientation orientation; - gint allocation; - gint position; - - g_return_val_if_fail ( - E_IS_MAIL_SHELL_CONTENT (mail_shell_content), 0); - - orientable = GTK_ORIENTABLE (mail_shell_content->priv->paned); - orientation = gtk_orientable_get_orientation (orientable); - - if (orientation == GTK_ORIENTATION_HORIZONTAL) - allocation = GTK_WIDGET (orientable)->allocation.width; - else - allocation = GTK_WIDGET (orientable)->allocation.height; - - position = gtk_paned_get_position (GTK_PANED (orientable)); - - return MAX (0, allocation - position); -} - -void -e_mail_shell_content_set_preview_size (EMailShellContent *mail_shell_content, - gint preview_size) -{ - GtkOrientable *orientable; - GtkOrientation orientation; - gint allocation; - gint position; - - g_return_if_fail (E_IS_MAIL_SHELL_CONTENT (mail_shell_content)); - - orientable = GTK_ORIENTABLE (mail_shell_content->priv->paned); - orientation = gtk_orientable_get_orientation (orientable); - - if (orientation == GTK_ORIENTATION_HORIZONTAL) - allocation = GTK_WIDGET (orientable)->allocation.width; - else - allocation = GTK_WIDGET (orientable)->allocation.height; - - position = MAX (0, allocation - preview_size); - gtk_paned_set_position (GTK_PANED (orientable), position); -} - gboolean e_mail_shell_content_get_preview_visible (EMailShellContent *mail_shell_content) { @@ -949,34 +849,13 @@ void e_mail_shell_content_set_vertical_view (EMailShellContent *mail_shell_content, gboolean vertical_view) { - GtkOrientable *orientable; - GtkOrientation orientation; - GConfBridge *bridge; - guint binding_id; - g_return_if_fail (E_IS_MAIL_SHELL_CONTENT (mail_shell_content)); - bridge = gconf_bridge_get (); - binding_id = mail_shell_content->priv->paned_binding_id; - - if (binding_id > 0) { - gconf_bridge_unbind (bridge, binding_id); - mail_shell_content->priv->paned_binding_id = 0; - } - - if (vertical_view) - orientation = GTK_ORIENTATION_HORIZONTAL; - else - orientation = GTK_ORIENTATION_VERTICAL; - - orientable = GTK_ORIENTABLE (mail_shell_content->priv->paned); - gtk_orientable_set_orientation (orientable, orientation); - mail_shell_content->priv->vertical_view = vertical_view; - e_mail_shell_content_update_view_instance (mail_shell_content); - g_object_notify (G_OBJECT (mail_shell_content), "vertical-view"); + + e_mail_shell_content_update_view_instance (mail_shell_content); } GalViewInstance * @@ -1015,6 +894,7 @@ e_mail_shell_content_set_search_strings (EMailShellContent *mail_shell_content, void e_mail_shell_content_update_view_instance (EMailShellContent *mail_shell_content) { + EPaned *paned; EMailReader *reader; EShellContent *shell_content; EShellView *shell_view; @@ -1052,8 +932,8 @@ e_mail_shell_content_update_view_instance (EMailShellContent *mail_shell_content view_instance = e_shell_view_new_view_instance (shell_view, view_id); mail_shell_content->priv->view_instance = view_instance; - show_vertical_view = - e_mail_shell_content_get_vertical_view (mail_shell_content); + paned = E_PANED (mail_shell_content->priv->paned); + show_vertical_view = e_paned_get_vertical_view (paned); if (show_vertical_view) { gchar *filename; diff --git a/modules/mail/e-mail-shell-content.h b/modules/mail/e-mail-shell-content.h index 48a0f9e234..57d2438705 100644 --- a/modules/mail/e-mail-shell-content.h +++ b/modules/mail/e-mail-shell-content.h @@ -65,11 +65,6 @@ GType e_mail_shell_content_get_type (void); void e_mail_shell_content_register_type (GTypeModule *type_module); GtkWidget * e_mail_shell_content_new(EShellView *shell_view); -gint e_mail_shell_content_get_preview_size - (EMailShellContent *mail_shell_content); -void e_mail_shell_content_set_preview_size - (EMailShellContent *mail_shell_content, - gint preview_size); gboolean e_mail_shell_content_get_preview_visible (EMailShellContent *mail_shell_content); void e_mail_shell_content_set_preview_visible diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am index ebd5562c30..29607758e5 100644 --- a/widgets/misc/Makefile.am +++ b/widgets/misc/Makefile.am @@ -67,6 +67,7 @@ widgetsinclude_HEADERS = \ e-map.h \ e-menu-tool-button.h \ e-online-button.h \ + e-paned.h \ e-popup-action.h \ e-popup-menu.h \ e-preferences-window.h \ @@ -130,6 +131,7 @@ libemiscwidgets_la_SOURCES = \ e-map.c \ e-menu-tool-button.c \ e-online-button.c \ + e-paned.c \ e-popup-action.c \ e-popup-menu.c \ e-preferences-window.c \ diff --git a/widgets/misc/e-paned.c b/widgets/misc/e-paned.c new file mode 100644 index 0000000000..350042413a --- /dev/null +++ b/widgets/misc/e-paned.c @@ -0,0 +1,344 @@ +/* + * e-paned.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "e-paned.h" + +#include <config.h> +#include <glib/gi18n-lib.h> + +#define E_PANED_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_PANED, EPanedPrivate)) + +struct _EPanedPrivate { + gint hposition; + gint vposition; + + guint sync_position : 1; +}; + +enum { + PROP_0, + PROP_HPOSITION, + PROP_VPOSITION, + PROP_VERTICAL_VIEW +}; + +static gpointer parent_class; + +static void +paned_notify_orientation_cb (EPaned *paned) +{ + paned->priv->sync_position = TRUE; + gtk_widget_queue_resize (GTK_WIDGET (paned)); + + g_object_notify (G_OBJECT (paned), "vertical-view"); +} + +static void +paned_notify_position_cb (EPaned *paned) +{ + GtkAllocation *allocation; + gint position; + + if (paned->priv->sync_position) + return; + + allocation = >K_WIDGET (paned)->allocation; + position = gtk_paned_get_position (GTK_PANED (paned)); + + if (e_paned_get_vertical_view (paned)) { + position = MAX (0, allocation->width - position); + e_paned_set_hposition (paned, position); + } else { + position = MAX (0, allocation->height - position); + e_paned_set_vposition (paned, position); + } +} + +static void +paned_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_HPOSITION: + e_paned_set_hposition ( + E_PANED (object), + g_value_get_int (value)); + return; + + case PROP_VPOSITION: + e_paned_set_vposition ( + E_PANED (object), + g_value_get_int (value)); + return; + + case PROP_VERTICAL_VIEW: + e_paned_set_vertical_view ( + E_PANED (object), + g_value_get_boolean (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +paned_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_HPOSITION: + g_value_set_int ( + value, e_paned_get_hposition ( + E_PANED (object))); + return; + + case PROP_VPOSITION: + g_value_set_int ( + value, e_paned_get_vposition ( + E_PANED (object))); + return; + + case PROP_VERTICAL_VIEW: + g_value_set_boolean ( + value, e_paned_get_vertical_view ( + E_PANED (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +paned_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + EPaned *paned = E_PANED (widget); + gint allocated; + gint position; + + /* Chain up to parent's size_allocate() method. */ + GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation); + + if (!paned->priv->sync_position) + return; + + if (e_paned_get_vertical_view (paned)) { + allocated = allocation->width; + position = e_paned_get_hposition (paned); + } else { + allocated = allocation->height; + position = e_paned_get_vposition (paned); + } + + position = MAX (0, allocated - position); + gtk_paned_set_position (GTK_PANED (paned), position); + + paned->priv->sync_position = FALSE; +} + +static void +paned_class_init (EPanedClass *class) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EPanedPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = paned_set_property; + object_class->get_property = paned_get_property; + + widget_class = GTK_WIDGET_CLASS (class); + widget_class->size_allocate = paned_size_allocate; + + g_object_class_install_property ( + object_class, + PROP_HPOSITION, + g_param_spec_int ( + "hposition", + _("Horizontal Position"), + _("Pane position when oriented horizontally"), + G_MININT, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_VPOSITION, + g_param_spec_int ( + "vposition", + _("Vertical Position"), + _("Pane position when oriented vertically"), + G_MININT, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_VERTICAL_VIEW, + g_param_spec_boolean ( + "vertical-view", + _("Vertical View"), + _("Whether vertical view is enabled"), + FALSE, + G_PARAM_READWRITE)); +} + +static void +paned_init (EPaned *paned) +{ + paned->priv = E_PANED_GET_PRIVATE (paned); + + g_signal_connect ( + paned, "notify::orientation", + G_CALLBACK (paned_notify_orientation_cb), NULL); + + g_signal_connect ( + paned, "notify::position", + G_CALLBACK (paned_notify_position_cb), NULL); +} + +GType +e_paned_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EPanedClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) paned_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EPaned), + 0, /* n_preallocs */ + (GInstanceInitFunc) paned_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GTK_TYPE_PANED, "EPaned", &type_info, 0); + } + + return type; +} + +GtkWidget * +e_paned_new (GtkOrientation orientation) +{ + return g_object_new (E_TYPE_PANED, "orientation", orientation, NULL); +} + +gint +e_paned_get_hposition (EPaned *paned) +{ + g_return_val_if_fail (E_IS_PANED (paned), 0); + + return paned->priv->hposition; +} + +void +e_paned_set_hposition (EPaned *paned, + gint hposition) +{ + g_return_if_fail (E_IS_PANED (paned)); + + if (hposition == paned->priv->hposition) + return; + + paned->priv->hposition = hposition; + + g_object_notify (G_OBJECT (paned), "hposition"); + + if (e_paned_get_vertical_view (paned)) { + paned->priv->sync_position = TRUE; + gtk_widget_queue_resize (GTK_WIDGET (paned)); + } +} + +gint +e_paned_get_vposition (EPaned *paned) +{ + g_return_val_if_fail (E_IS_PANED (paned), 0); + + return paned->priv->vposition; +} + +void +e_paned_set_vposition (EPaned *paned, + gint vposition) +{ + g_return_if_fail (E_IS_PANED (paned)); + + if (vposition == paned->priv->vposition) + return; + + paned->priv->vposition = vposition; + + g_object_notify (G_OBJECT (paned), "vposition"); + + if (!e_paned_get_vertical_view (paned)) { + paned->priv->sync_position = TRUE; + gtk_widget_queue_resize (GTK_WIDGET (paned)); + } +} + +gboolean +e_paned_get_vertical_view (EPaned *paned) +{ + GtkOrientable *orientable; + GtkOrientation orientation; + + g_return_val_if_fail (E_IS_PANED (paned), FALSE); + + orientable = GTK_ORIENTABLE (paned); + orientation = gtk_orientable_get_orientation (orientable); + + return (orientation == GTK_ORIENTATION_HORIZONTAL); +} + +void +e_paned_set_vertical_view (EPaned *paned, + gboolean vertical_view) +{ + GtkOrientable *orientable; + GtkOrientation orientation; + + g_return_if_fail (E_IS_PANED (paned)); + + if (vertical_view) + orientation = GTK_ORIENTATION_HORIZONTAL; + else + orientation = GTK_ORIENTATION_VERTICAL; + + orientable = GTK_ORIENTABLE (paned); + gtk_orientable_set_orientation (orientable, orientation); +} diff --git a/widgets/misc/e-paned.h b/widgets/misc/e-paned.h new file mode 100644 index 0000000000..ea37cbab21 --- /dev/null +++ b/widgets/misc/e-paned.h @@ -0,0 +1,75 @@ +/* + * e-paned.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef E_PANED_H +#define E_PANED_H + +#include <gtk/gtk.h> + +/* Standard GObject macros */ +#define E_TYPE_PANED \ + (e_paned_get_type ()) +#define E_PANED(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_PANED, EPaned)) +#define E_PANED_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_PANED, EPanedClass)) +#define E_IS_PANED(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_PANED)) +#define E_IS_PANED_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_PANED)) +#define E_PANED_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_PANED, EPanedClass)) + +G_BEGIN_DECLS + +typedef struct _EPaned EPaned; +typedef struct _EPanedClass EPanedClass; +typedef struct _EPanedPrivate EPanedPrivate; + +struct _EPaned { + GtkPaned parent; + EPanedPrivate *priv; +}; + +struct _EPanedClass { + GtkPanedClass parent_class; +}; + +GType e_paned_get_type (void); +GtkWidget * e_paned_new (GtkOrientation orientation); +gint e_paned_get_hposition (EPaned *paned); +void e_paned_set_hposition (EPaned *paned, + gint hposition); +gint e_paned_get_vposition (EPaned *paned); +void e_paned_set_vposition (EPaned *paned, + gint vposition); +gboolean e_paned_get_vertical_view (EPaned *paned); +void e_paned_set_vertical_view (EPaned *paned, + gboolean vertical_view); + +G_END_DECLS + +#endif /* E_PANED_H */ |