diff options
author | Matthew Barnes <mbarnes@src.gnome.org> | 2009-04-08 05:40:49 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2009-04-08 05:40:49 +0800 |
commit | a843a2a4d205ef45d8a5670cf0b17c238cee1f37 (patch) | |
tree | 9979d5ade1368251151a2007822e47a9eb8cfe19 | |
parent | a312ad7cf1c2c34577914a2f0f2a5ca191378103 (diff) | |
download | gsoc2013-evolution-a843a2a4d205ef45d8a5670cf0b17c238cee1f37.tar.gz gsoc2013-evolution-a843a2a4d205ef45d8a5670cf0b17c238cee1f37.tar.zst gsoc2013-evolution-a843a2a4d205ef45d8a5670cf0b17c238cee1f37.zip |
Attachment rewrite pretty much complete. Just testing now.
svn path=/branches/kill-bonobo/; revision=37504
-rw-r--r-- | addressbook/gui/contact-editor/e-contact-editor.c | 1 | ||||
-rw-r--r-- | calendar/gui/e-meeting-time-sel.c | 1 | ||||
-rw-r--r-- | mail/Makefile.am | 2 | ||||
-rw-r--r-- | mail/e-mail-attachment-bar.c | 12 | ||||
-rw-r--r-- | mail/e-mail-attachment-button.c | 542 | ||||
-rw-r--r-- | mail/e-mail-attachment-button.h | 90 | ||||
-rw-r--r-- | mail/em-format-html-display.c | 27 | ||||
-rw-r--r-- | widgets/misc/Makefile.am | 4 | ||||
-rw-r--r-- | widgets/misc/e-attachment-button.c | 695 | ||||
-rw-r--r-- | widgets/misc/e-attachment-button.h | 83 | ||||
-rw-r--r-- | widgets/misc/e-attachment-icon-view.c | 2 | ||||
-rw-r--r-- | widgets/misc/e-attachment-paned.c | 12 | ||||
-rw-r--r-- | widgets/misc/e-attachment-store.c | 9 | ||||
-rw-r--r-- | widgets/misc/e-attachment-tree-view.c | 2 | ||||
-rw-r--r-- | widgets/misc/e-attachment-view.c | 35 | ||||
-rw-r--r-- | widgets/misc/e-attachment-view.h | 5 | ||||
-rw-r--r-- | widgets/misc/e-attachment.c | 15 | ||||
-rw-r--r-- | widgets/misc/e-menu-button.c | 497 | ||||
-rw-r--r-- | widgets/misc/e-menu-button.h | 74 |
19 files changed, 1432 insertions, 676 deletions
diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c index 4bead3cc22..24b807cf3a 100644 --- a/addressbook/gui/contact-editor/e-contact-editor.c +++ b/addressbook/gui/contact-editor/e-contact-editor.c @@ -33,7 +33,6 @@ #include <gdk-pixbuf/gdk-pixbuf.h> #include <libedataserverui/e-categories-dialog.h> -#include "misc/e-gui-utils.h" #include <libebook/e-address-western.h> #include <libedataserverui/e-category-completion.h> diff --git a/calendar/gui/e-meeting-time-sel.c b/calendar/gui/e-meeting-time-sel.c index 6b500fe9f2..80a238e8a7 100644 --- a/calendar/gui/e-meeting-time-sel.c +++ b/calendar/gui/e-meeting-time-sel.c @@ -40,7 +40,6 @@ #include "misc/e-canvas-utils.h" #include "misc/e-dateedit.h" -#include "misc/e-gui-utils.h" #include "e-util/e-cursor.h" #include "e-util/e-util.h" diff --git a/mail/Makefile.am b/mail/Makefile.am index 82fdf04096..8039bfe52d 100644 --- a/mail/Makefile.am +++ b/mail/Makefile.am @@ -39,8 +39,6 @@ libevolution_module_mail_la_SOURCES = \ e-attachment-handler-mail.h \ e-mail-attachment-bar.c \ e-mail-attachment-bar.h \ - e-mail-attachment-button.c \ - e-mail-attachment-button.h \ e-mail-browser.c \ e-mail-browser.h \ e-mail-display.c \ diff --git a/mail/e-mail-attachment-bar.c b/mail/e-mail-attachment-bar.c index 533623e066..5323a7d359 100644 --- a/mail/e-mail-attachment-bar.c +++ b/mail/e-mail-attachment-bar.c @@ -420,6 +420,17 @@ mail_attachment_bar_unselect_all (EAttachmentView *view) } static void +mail_attachment_bar_update_actions (EAttachmentView *view) +{ + EMailAttachmentBarPrivate *priv; + + priv = E_MAIL_ATTACHMENT_BAR_GET_PRIVATE (view); + view = E_ATTACHMENT_VIEW (priv->icon_view); + + e_attachment_view_update_actions (view); +} + +static void mail_attachment_bar_class_init (EMailAttachmentBarClass *class) { GObjectClass *object_class; @@ -477,6 +488,7 @@ mail_attachment_bar_iface_init (EAttachmentViewIface *iface) iface->unselect_path = mail_attachment_bar_unselect_path; iface->select_all = mail_attachment_bar_select_all; iface->unselect_all = mail_attachment_bar_unselect_all; + iface->update_actions = mail_attachment_bar_update_actions; } static void diff --git a/mail/e-mail-attachment-button.c b/mail/e-mail-attachment-button.c deleted file mode 100644 index 1fe65df3b3..0000000000 --- a/mail/e-mail-attachment-button.c +++ /dev/null @@ -1,542 +0,0 @@ -/* - * e-mail-attachment-button.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-mail-attachment-button.h" - -#include "e-util/e-binding.h" - -#define E_MAIL_ATTACHMENT_BUTTON_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_MAIL_ATTACHMENT_BUTTON, EMailAttachmentButtonPrivate)) - -struct _EMailAttachmentButtonPrivate { - - EAttachmentView *view; - EAttachment *attachment; - gulong reference_handler_id; - - GtkWidget *inline_button; - GtkWidget *action_button; - GtkWidget *cell_view; - - guint expandable : 1; - guint expanded : 1; -}; - -enum { - PROP_0, - PROP_ATTACHMENT, - PROP_EXPANDABLE, - PROP_EXPANDED, - PROP_VIEW -}; - -enum { - CLICKED, - LAST_SIGNAL -}; - -static gpointer parent_class; -static gulong signals[LAST_SIGNAL]; - -static void -mail_attachment_button_action_clicked_cb (EMailAttachmentButton *button) -{ -} - -static void -mail_attachment_button_update_cell_view (EMailAttachmentButton *button) -{ - GtkCellView *cell_view; - EAttachment *attachment; - GtkTreeRowReference *reference; - GtkTreeModel *model = NULL; - GtkTreePath *path = NULL; - - cell_view = GTK_CELL_VIEW (button->priv->cell_view); - - attachment = e_mail_attachment_button_get_attachment (button); - if (attachment == NULL) - goto exit; - - reference = e_attachment_get_reference (attachment); - if (reference == NULL) - goto exit; - - model = gtk_tree_row_reference_get_model (reference); - path = gtk_tree_row_reference_get_path (reference); - -exit: - gtk_cell_view_set_model (cell_view, model); - gtk_cell_view_set_displayed_row (cell_view, path); - - if (path != NULL) - gtk_tree_path_free (path); -} - -static void -mail_attachment_button_update_pixbufs (EMailAttachmentButton *button) -{ - GtkCellView *cell_view; - GtkCellRenderer *renderer; - GtkIconTheme *icon_theme; - GdkPixbuf *pixbuf_expander_open; - GdkPixbuf *pixbuf_expander_closed; - GList *list; - - icon_theme = gtk_icon_theme_get_default (); - - /* Grab the first cell renderer. */ - cell_view = GTK_CELL_VIEW (button->priv->cell_view); - list = gtk_cell_view_get_cell_renderers (cell_view); - renderer = GTK_CELL_RENDERER (list->data); - g_list_free (list); - - pixbuf_expander_open = gtk_widget_render_icon ( - GTK_WIDGET (button), GTK_STOCK_GO_DOWN, - GTK_ICON_SIZE_BUTTON, NULL); - - pixbuf_expander_closed = gtk_widget_render_icon ( - GTK_WIDGET (button), GTK_STOCK_GO_FORWARD, - GTK_ICON_SIZE_BUTTON, NULL); - - g_object_set ( - renderer, - "pixbuf-expander-open", pixbuf_expander_open, - "pixbuf-expander-closed", pixbuf_expander_closed, - NULL); - - g_object_unref (pixbuf_expander_open); - g_object_unref (pixbuf_expander_closed); -} - -static void -mail_attachment_button_set_view (EMailAttachmentButton *button, - EAttachmentView *view) -{ - g_return_if_fail (button->priv->view == NULL); - - button->priv->view = g_object_ref (view); -} - -static void -mail_attachment_button_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_ATTACHMENT: - e_mail_attachment_button_set_attachment ( - E_MAIL_ATTACHMENT_BUTTON (object), - g_value_get_object (value)); - return; - - case PROP_EXPANDABLE: - e_mail_attachment_button_set_expandable ( - E_MAIL_ATTACHMENT_BUTTON (object), - g_value_get_boolean (value)); - return; - - case PROP_EXPANDED: - e_mail_attachment_button_set_expanded ( - E_MAIL_ATTACHMENT_BUTTON (object), - g_value_get_boolean (value)); - return; - - case PROP_VIEW: - mail_attachment_button_set_view ( - E_MAIL_ATTACHMENT_BUTTON (object), - g_value_get_object (value)); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -mail_attachment_button_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_ATTACHMENT: - g_value_set_object ( - value, - e_mail_attachment_button_get_attachment ( - E_MAIL_ATTACHMENT_BUTTON (object))); - return; - - case PROP_EXPANDABLE: - g_value_set_boolean ( - value, - e_mail_attachment_button_get_expandable ( - E_MAIL_ATTACHMENT_BUTTON (object))); - return; - - case PROP_EXPANDED: - g_value_set_boolean ( - value, - e_mail_attachment_button_get_expanded ( - E_MAIL_ATTACHMENT_BUTTON (object))); - return; - - case PROP_VIEW: - g_value_set_object ( - value, - e_mail_attachment_button_get_view ( - E_MAIL_ATTACHMENT_BUTTON (object))); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -mail_attachment_button_dispose (GObject *object) -{ - EMailAttachmentButtonPrivate *priv; - - priv = E_MAIL_ATTACHMENT_BUTTON_GET_PRIVATE (object); - - if (priv->view != NULL) { - g_object_unref (priv->view); - priv->view = NULL; - } - - if (priv->attachment != NULL) { - g_signal_handler_disconnect ( - priv->attachment, - priv->reference_handler_id); - g_object_unref (priv->attachment); - priv->attachment = NULL; - } - - if (priv->inline_button != NULL) { - g_object_unref (priv->inline_button); - priv->inline_button = NULL; - } - - if (priv->action_button != NULL) { - g_object_unref (priv->action_button); - priv->action_button = NULL; - } - - if (priv->cell_view != NULL) { - g_object_unref (priv->cell_view); - priv->cell_view = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (parent_class)->dispose (object); -} - -static void -mail_attachment_button_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ - EMailAttachmentButton *button; - - /* Chain up to parent's style_set() method. */ - GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style); - - button = E_MAIL_ATTACHMENT_BUTTON (widget); - mail_attachment_button_update_pixbufs (button); -} - -static void -mail_attachment_button_class_init (EMailAttachmentButtonClass *class) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - - parent_class = g_type_class_peek_parent (class); - g_type_class_add_private (class, sizeof (EMailAttachmentButtonPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->set_property = mail_attachment_button_set_property; - object_class->get_property = mail_attachment_button_get_property; - object_class->dispose = mail_attachment_button_dispose; - - widget_class = GTK_WIDGET_CLASS (class); - widget_class->style_set = mail_attachment_button_style_set; - - g_object_class_install_property ( - object_class, - PROP_ATTACHMENT, - g_param_spec_object ( - "attachment", - "Attachment", - NULL, - E_TYPE_ATTACHMENT, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_EXPANDABLE, - g_param_spec_boolean ( - "expandable", - "Expandable", - NULL, - TRUE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property ( - object_class, - PROP_EXPANDED, - g_param_spec_boolean ( - "expanded", - "Expanded", - NULL, - FALSE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property ( - object_class, - PROP_VIEW, - g_param_spec_object ( - "view", - "View", - NULL, - E_TYPE_ATTACHMENT_VIEW, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - - signals[CLICKED] = g_signal_new ( - "clicked", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (EMailAttachmentButtonClass, clicked), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - -static void -mail_attachment_button_init (EMailAttachmentButton *button) -{ - GtkCellRenderer *renderer; - GtkCellLayout *cell_layout; - GtkWidget *container; - GtkWidget *widget; - - button->priv = E_MAIL_ATTACHMENT_BUTTON_GET_PRIVATE (button); - - /* Configure Widgets */ - - container = GTK_WIDGET (button); - - widget = gtk_button_new (); - gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); - button->priv->inline_button = g_object_ref (widget); - gtk_widget_show (widget); - - e_binding_new ( - G_OBJECT (button), "expandable", - G_OBJECT (widget), "sensitive"); - - widget = gtk_button_new (); - gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); - button->priv->action_button = g_object_ref (widget); - gtk_widget_show (widget); - - container = button->priv->inline_button; - - widget = gtk_cell_view_new (); - gtk_container_add (GTK_CONTAINER (container), widget); - button->priv->cell_view = g_object_ref (widget); - gtk_widget_show (widget); - - container = button->priv->action_button; - - widget = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); - gtk_container_add (GTK_CONTAINER (container), widget); - gtk_widget_show (widget); - - /* Configure Renderers */ - - cell_layout = GTK_CELL_LAYOUT (button->priv->cell_view); - - renderer = gtk_cell_renderer_pixbuf_new (); - g_object_set (renderer, "is-expander", TRUE, NULL); - gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); - - e_mutual_binding_new ( - G_OBJECT (button), "expanded", - G_OBJECT (renderer), "is-expanded"); - - renderer = gtk_cell_renderer_pixbuf_new (); - g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL); - gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); - - gtk_cell_layout_add_attribute ( - cell_layout, renderer, "gicon", - E_ATTACHMENT_STORE_COLUMN_ICON); - - /* Configure Signal Handlers */ - - g_signal_connect_swapped ( - button->priv->action_button, "clicked", - G_CALLBACK (mail_attachment_button_action_clicked_cb), button); - - g_signal_connect_swapped ( - button->priv->inline_button, "clicked", - G_CALLBACK (e_mail_attachment_button_clicked), button); -} - -GType -e_mail_attachment_button_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) { - static const GTypeInfo type_info = { - sizeof (EMailAttachmentButtonClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) mail_attachment_button_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (EMailAttachmentButton), - 0, /* n_preallocs */ - (GInstanceInitFunc) mail_attachment_button_init, - NULL /* value_table */ - }; - - type = g_type_register_static ( - GTK_TYPE_HBOX, "EMailAttachmentButton", &type_info, 0); - } - - return type; -} - -GtkWidget * -e_mail_attachment_button_new (EAttachmentView *view) -{ - g_return_val_if_fail (E_IS_ATTACHMENT_VIEW (view), NULL); - - return g_object_new ( - E_TYPE_MAIL_ATTACHMENT_BUTTON, - "view", view, NULL); -} - -EAttachmentView * -e_mail_attachment_button_get_view (EMailAttachmentButton *button) -{ - g_return_val_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button), NULL); - - return button->priv->view; -} - -EAttachment * -e_mail_attachment_button_get_attachment (EMailAttachmentButton *button) -{ - g_return_val_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button), NULL); - - return button->priv->attachment; -} - -void -e_mail_attachment_button_set_attachment (EMailAttachmentButton *button, - EAttachment *attachment) -{ - g_return_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button)); - - if (attachment != NULL) { - g_return_if_fail (E_IS_ATTACHMENT (attachment)); - g_object_ref (attachment); - } - - if (button->priv->attachment != NULL) { - g_signal_handler_disconnect ( - button->priv->attachment, - button->priv->reference_handler_id); - g_object_unref (button->priv->attachment); - } - - button->priv->attachment = attachment; - - if (attachment != NULL) { - gulong handler_id; - - handler_id = g_signal_connect_swapped ( - attachment, "notify::reference", - G_CALLBACK (mail_attachment_button_update_cell_view), - button); - mail_attachment_button_update_cell_view (button); - mail_attachment_button_update_pixbufs (button); - button->priv->reference_handler_id = handler_id; - } - - g_object_notify (G_OBJECT (button), "attachment"); -} - -gboolean -e_mail_attachment_button_get_expandable (EMailAttachmentButton *button) -{ - g_return_val_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button), FALSE); - - return button->priv->expandable; -} - -void -e_mail_attachment_button_set_expandable (EMailAttachmentButton *button, - gboolean expandable) -{ - g_return_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button)); - - button->priv->expandable = expandable; - - if (!expandable) - e_mail_attachment_button_set_expanded (button, FALSE); - - g_object_notify (G_OBJECT (button), "expandable"); -} - -gboolean -e_mail_attachment_button_get_expanded (EMailAttachmentButton *button) -{ - g_return_val_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button), FALSE); - - return button->priv->expanded; -} - -void -e_mail_attachment_button_set_expanded (EMailAttachmentButton *button, - gboolean expanded) -{ - g_return_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button)); - - button->priv->expanded = expanded; - - g_object_notify (G_OBJECT (button), "expanded"); -} - -void -e_mail_attachment_button_clicked (EMailAttachmentButton *button) -{ - g_return_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button)); - - g_signal_emit (button, signals[CLICKED], 0); -} diff --git a/mail/e-mail-attachment-button.h b/mail/e-mail-attachment-button.h deleted file mode 100644 index 26ec5cf0d6..0000000000 --- a/mail/e-mail-attachment-button.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * e-mail-attachment-button.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_MAIL_ATTACHMENT_BUTTON_H -#define E_MAIL_ATTACHMENT_BUTTON_H - -#include <gtk/gtk.h> -#include <widgets/misc/e-attachment.h> -#include <widgets/misc/e-attachment-view.h> - -/* Standard GObject macros */ -#define E_TYPE_MAIL_ATTACHMENT_BUTTON \ - (e_mail_attachment_button_get_type ()) -#define E_MAIL_ATTACHMENT_BUTTON(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_MAIL_ATTACHMENT_BUTTON, EMailAttachmentButton)) -#define E_MAIL_ATTACHMENT_BUTTON_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_MAIL_ATTACHMENT_BUTTON, EMailAttachmentButtonClass)) -#define E_IS_MAIL_ATTACHMENT_BUTTON(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_MAIL_ATTACHMENT_BUTTON)) -#define E_IS_MAIL_ATTACHMENT_BUTTON_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_MAIL_ATTACHMENT_BUTTON)) -#define E_MAIL_ATTACHMENT_BUTTON_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_MAIL_ATTACHMENT_BUTTON, EMailAttachmentButtonClass)) - -G_BEGIN_DECLS - -typedef struct _EMailAttachmentButton EMailAttachmentButton; -typedef struct _EMailAttachmentButtonClass EMailAttachmentButtonClass; -typedef struct _EMailAttachmentButtonPrivate EMailAttachmentButtonPrivate; - -struct _EMailAttachmentButton { - GtkHBox parent; - EMailAttachmentButtonPrivate *priv; -}; - -struct _EMailAttachmentButtonClass { - GtkHBoxClass parent_class; - - /* Signals */ - void (*clicked) (EMailAttachmentButton *button); -}; - -GType e_mail_attachment_button_get_type (void); -GtkWidget * e_mail_attachment_button_new (EAttachmentView *view); -void e_mail_attachment_button_clicked(EMailAttachmentButton *button); -EAttachmentView * - e_mail_attachment_button_get_view - (EMailAttachmentButton *button); -EAttachment * e_mail_attachment_button_get_attachment - (EMailAttachmentButton *button); -void e_mail_attachment_button_set_attachment - (EMailAttachmentButton *button, - EAttachment *attachment); -gboolean e_mail_attachment_button_get_expandable - (EMailAttachmentButton *button); -void e_mail_attachment_button_set_expandable - (EMailAttachmentButton *button, - gboolean expandable); -gboolean e_mail_attachment_button_get_expanded - (EMailAttachmentButton *button); -void e_mail_attachment_button_set_expanded - (EMailAttachmentButton *button, - gboolean expanded); - -G_END_DECLS - -#endif /* E_MAIL_ATTACHMENT_BUTTON_H */ diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c index 5faa671fd8..de965135c8 100644 --- a/mail/em-format-html-display.c +++ b/mail/em-format-html-display.c @@ -75,11 +75,11 @@ #include "e-mail-display.h" #include "e-mail-attachment-bar.h" -#include "e-mail-attachment-button.h" #include "em-format-html-display.h" #include "em-icon-stream.h" #include "em-utils.h" #include "em-popup.h" +#include "widgets/misc/e-attachment-button.h" #include "widgets/misc/e-attachment-view.h" #ifdef G_OS_WIN32 @@ -855,8 +855,9 @@ efhd_attachment_show(EPopup *ep, EPopupItem *item, void *data) } static void -efhd_attachment_button_clicked (GtkWidget *widget, - struct _attach_puri *info) +efhd_attachment_button_expanded (GtkWidget *widget, + GParamSpec *pspec, + struct _attach_puri *info) { if (!efhd_can_process_attachment (widget)) return; @@ -1242,21 +1243,21 @@ efhd_attachment_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje info->attachment, (GAsyncReadyCallback) e_attachment_load_handle_error, parent); - widget = e_mail_attachment_button_new (view); - e_mail_attachment_button_set_attachment ( - E_MAIL_ATTACHMENT_BUTTON (widget), attachment); - e_mail_attachment_button_set_expandable ( - E_MAIL_ATTACHMENT_BUTTON (widget), (info->handle != NULL)); - e_mail_attachment_button_set_expanded ( - E_MAIL_ATTACHMENT_BUTTON (widget), info->shown); + widget = e_attachment_button_new (view); + e_attachment_button_set_attachment ( + E_ATTACHMENT_BUTTON (widget), attachment); + e_attachment_button_set_expandable ( + E_ATTACHMENT_BUTTON (widget), (info->handle != NULL)); + e_attachment_button_set_expanded ( + E_ATTACHMENT_BUTTON (widget), info->shown); gtk_container_add (GTK_CONTAINER (eb), widget); gtk_widget_show (widget); g_object_set_data (G_OBJECT (widget), "efh", efh); g_signal_connect ( - widget, "clicked", - G_CALLBACK (efhd_attachment_button_clicked), info); + widget, "notify::expanded", + G_CALLBACK (efhd_attachment_button_expanded), info); #if 0 /* FIXME: offline parts, just get icon */ @@ -1294,8 +1295,6 @@ efhd_attachment_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje return TRUE; } -/* not used currently */ -/* frame source callback */ static void efhd_attachment_frame (EMFormat *emf, CamelStream *stream, diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am index 8ba66287f8..ce22c3b065 100644 --- a/widgets/misc/Makefile.am +++ b/widgets/misc/Makefile.am @@ -40,6 +40,7 @@ widgetsinclude_HEADERS = \ e-activity-proxy.h \ e-alert-activity.h \ e-attachment.h \ + e-attachment-button.h \ e-attachment-dialog.h \ e-attachment-handler.h \ e-attachment-handler-image.h \ @@ -69,6 +70,7 @@ widgetsinclude_HEADERS = \ e-icon-entry.h \ e-image-chooser.h \ e-map.h \ + e-menu-button.h \ e-menu-tool-button.h \ e-online-button.h \ e-popup-action.h \ @@ -103,6 +105,7 @@ libemiscwidgets_la_SOURCES = \ e-activity-proxy.c \ e-alert-activity.c \ e-attachment.c \ + e-attachment-button.c \ e-attachment-dialog.c \ e-attachment-handler.c \ e-attachment-handler-image.c \ @@ -132,6 +135,7 @@ libemiscwidgets_la_SOURCES = \ e-icon-entry.c \ e-image-chooser.c \ e-map.c \ + e-menu-button.c \ e-menu-tool-button.c \ e-online-button.c \ e-popup-action.c \ diff --git a/widgets/misc/e-attachment-button.c b/widgets/misc/e-attachment-button.c new file mode 100644 index 0000000000..fa43373a3c --- /dev/null +++ b/widgets/misc/e-attachment-button.c @@ -0,0 +1,695 @@ +/* + * e-attachment-button.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) + * + */ + +/* Much of the popup menu logic here was ripped from GtkMenuToolButton. */ + +#include "e-attachment-button.h" + +#include "e-util/e-binding.h" + +#define E_ATTACHMENT_BUTTON_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_ATTACHMENT_BUTTON, EAttachmentButtonPrivate)) + +struct _EAttachmentButtonPrivate { + + EAttachmentView *view; + EAttachment *attachment; + gulong reference_handler_id; + + GtkWidget *expand_button; + GtkWidget *toggle_button; + GtkWidget *cell_view; + + guint expandable : 1; + guint expanded : 1; +}; + +enum { + PROP_0, + PROP_ATTACHMENT, + PROP_EXPANDABLE, + PROP_EXPANDED, + PROP_VIEW +}; + +static gpointer parent_class; + +static void +attachment_button_menu_deactivate_cb (EAttachmentButton *button) +{ + GtkToggleButton *toggle_button; + + toggle_button = GTK_TOGGLE_BUTTON (button->priv->toggle_button); + + gtk_toggle_button_set_active (toggle_button, FALSE); +} + +static void +attachment_button_menu_position (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, + EAttachmentButton *button) +{ + GtkRequisition menu_requisition; + GtkTextDirection direction; + GdkRectangle monitor; + GdkScreen *screen; + GdkWindow *window; + GtkWidget *widget; + GtkWidget *toggle_button; + gint monitor_num; + + widget = GTK_WIDGET (button); + toggle_button = button->priv->toggle_button; + gtk_widget_size_request (GTK_WIDGET (menu), &menu_requisition); + + window = gtk_widget_get_parent_window (widget); + screen = gtk_widget_get_screen (GTK_WIDGET (menu)); + monitor_num = gdk_screen_get_monitor_at_window (screen, window); + if (monitor_num < 0) + monitor_num = 0; + gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); + + gdk_window_get_origin (window, x, y); + *x += widget->allocation.x; + *y += widget->allocation.y; + + direction = gtk_widget_get_direction (widget); + if (direction == GTK_TEXT_DIR_LTR) + x += MAX (widget->allocation.width - menu_requisition.width, 0); + else if (menu_requisition.width > widget->allocation.width) + x -= menu_requisition.width - widget->allocation.width; + + if ((*y + toggle_button->allocation.height + menu_requisition.height) <= monitor.y + monitor.height) + *y += toggle_button->allocation.height; + else if ((*y - menu_requisition.height) >= monitor.y) + *y -= menu_requisition.height; + else if (monitor.y + monitor.height - (*y + toggle_button->allocation.height) > *y) + *y += toggle_button->allocation.height; + else + *y -= menu_requisition.height; + + *push_in = FALSE; +} + +static void +attachment_button_select_path (EAttachmentButton *button) +{ + EAttachmentView *view; + EAttachment *attachment; + GtkTreeRowReference *reference; + GtkTreePath *path; + + attachment = e_attachment_button_get_attachment (button); + g_return_if_fail (E_IS_ATTACHMENT (attachment)); + + reference = e_attachment_get_reference (attachment); + g_return_if_fail (gtk_tree_row_reference_valid (reference)); + + view = e_attachment_button_get_view (button); + path = gtk_tree_row_reference_get_path (reference); + + e_attachment_view_unselect_all (view); + e_attachment_view_select_path (view, path); + + gtk_tree_path_free (path); +} + +static void +attachment_button_show_popup_menu (EAttachmentButton *button, + GdkEventButton *event) +{ + GtkToggleButton *toggle_button; + EAttachmentView *view; + + view = e_attachment_button_get_view (button); + toggle_button = GTK_TOGGLE_BUTTON (button->priv->toggle_button); + + attachment_button_select_path (button); + gtk_toggle_button_set_active (toggle_button, TRUE); + + e_attachment_view_show_popup_menu ( + view, event, (GtkMenuPositionFunc) + attachment_button_menu_position, button); + +} + +static void +attachment_button_update_cell_view (EAttachmentButton *button) +{ + GtkCellView *cell_view; + EAttachment *attachment; + GtkTreeRowReference *reference; + GtkTreeModel *model = NULL; + GtkTreePath *path = NULL; + + cell_view = GTK_CELL_VIEW (button->priv->cell_view); + + attachment = e_attachment_button_get_attachment (button); + if (attachment == NULL) + goto exit; + + reference = e_attachment_get_reference (attachment); + if (reference == NULL) + goto exit; + + model = gtk_tree_row_reference_get_model (reference); + path = gtk_tree_row_reference_get_path (reference); + +exit: + gtk_cell_view_set_model (cell_view, model); + gtk_cell_view_set_displayed_row (cell_view, path); + + if (path != NULL) + gtk_tree_path_free (path); +} + +static void +attachment_button_update_pixbufs (EAttachmentButton *button) +{ + GtkCellView *cell_view; + GtkCellRenderer *renderer; + GtkIconTheme *icon_theme; + GdkPixbuf *pixbuf_expander_open; + GdkPixbuf *pixbuf_expander_closed; + GList *list; + + icon_theme = gtk_icon_theme_get_default (); + + /* Grab the first cell renderer. */ + cell_view = GTK_CELL_VIEW (button->priv->cell_view); + list = gtk_cell_view_get_cell_renderers (cell_view); + renderer = GTK_CELL_RENDERER (list->data); + g_list_free (list); + + pixbuf_expander_open = gtk_widget_render_icon ( + GTK_WIDGET (button), GTK_STOCK_GO_DOWN, + GTK_ICON_SIZE_BUTTON, NULL); + + pixbuf_expander_closed = gtk_widget_render_icon ( + GTK_WIDGET (button), GTK_STOCK_GO_FORWARD, + GTK_ICON_SIZE_BUTTON, NULL); + + g_object_set ( + renderer, + "pixbuf-expander-open", pixbuf_expander_open, + "pixbuf-expander-closed", pixbuf_expander_closed, + NULL); + + g_object_unref (pixbuf_expander_open); + g_object_unref (pixbuf_expander_closed); +} + +static void +attachment_button_expand_clicked_cb (EAttachmentButton *button) +{ + gboolean expanded; + + expanded = e_attachment_button_get_expanded (button); + e_attachment_button_set_expanded (button, !expanded); +} + +static void +attachment_button_expand_drag_data_get_cb (EAttachmentButton *button, + GdkDragContext *context, + GtkSelectionData *selection, + guint info, + guint time) +{ + EAttachmentView *view; + + attachment_button_select_path (button); + + view = e_attachment_button_get_view (button); + + e_attachment_view_drag_data_get ( + view, context, selection, info, time); +} + +static gboolean +attachment_button_toggle_button_press_event_cb (EAttachmentButton *button, + GdkEventButton *event) +{ + if (event->button == 1) { + attachment_button_show_popup_menu (button, event); + return TRUE; + } + + return FALSE; +} + +static void +attachment_button_set_view (EAttachmentButton *button, + EAttachmentView *view) +{ + GtkWidget *menu; + + g_return_if_fail (button->priv->view == NULL); + + button->priv->view = g_object_ref (view); + + menu = e_attachment_view_get_popup_menu (view); + + g_signal_connect_swapped ( + menu, "deactivate", + G_CALLBACK (attachment_button_menu_deactivate_cb), button); +} + +static void +attachment_button_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_ATTACHMENT: + e_attachment_button_set_attachment ( + E_ATTACHMENT_BUTTON (object), + g_value_get_object (value)); + return; + + case PROP_EXPANDABLE: + e_attachment_button_set_expandable ( + E_ATTACHMENT_BUTTON (object), + g_value_get_boolean (value)); + return; + + case PROP_EXPANDED: + e_attachment_button_set_expanded ( + E_ATTACHMENT_BUTTON (object), + g_value_get_boolean (value)); + return; + + case PROP_VIEW: + attachment_button_set_view ( + E_ATTACHMENT_BUTTON (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +attachment_button_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_ATTACHMENT: + g_value_set_object ( + value, + e_attachment_button_get_attachment ( + E_ATTACHMENT_BUTTON (object))); + return; + + case PROP_EXPANDABLE: + g_value_set_boolean ( + value, + e_attachment_button_get_expandable ( + E_ATTACHMENT_BUTTON (object))); + return; + + case PROP_EXPANDED: + g_value_set_boolean ( + value, + e_attachment_button_get_expanded ( + E_ATTACHMENT_BUTTON (object))); + return; + + case PROP_VIEW: + g_value_set_object ( + value, + e_attachment_button_get_view ( + E_ATTACHMENT_BUTTON (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +attachment_button_dispose (GObject *object) +{ + EAttachmentButtonPrivate *priv; + + priv = E_ATTACHMENT_BUTTON_GET_PRIVATE (object); + + if (priv->view != NULL) { + g_object_unref (priv->view); + priv->view = NULL; + } + + if (priv->attachment != NULL) { + g_signal_handler_disconnect ( + priv->attachment, + priv->reference_handler_id); + g_object_unref (priv->attachment); + priv->attachment = NULL; + } + + if (priv->expand_button != NULL) { + g_object_unref (priv->expand_button); + priv->expand_button = NULL; + } + + if (priv->toggle_button != NULL) { + g_object_unref (priv->toggle_button); + priv->toggle_button = NULL; + } + + if (priv->cell_view != NULL) { + g_object_unref (priv->cell_view); + priv->cell_view = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +attachment_button_style_set (GtkWidget *widget, + GtkStyle *previous_style) +{ + EAttachmentButton *button; + + /* Chain up to parent's style_set() method. */ + GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style); + + button = E_ATTACHMENT_BUTTON (widget); + attachment_button_update_pixbufs (button); +} + +static void +attachment_button_class_init (EAttachmentButtonClass *class) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EAttachmentButtonPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = attachment_button_set_property; + object_class->get_property = attachment_button_get_property; + object_class->dispose = attachment_button_dispose; + + widget_class = GTK_WIDGET_CLASS (class); + widget_class->style_set = attachment_button_style_set; + + g_object_class_install_property ( + object_class, + PROP_ATTACHMENT, + g_param_spec_object ( + "attachment", + "Attachment", + NULL, + E_TYPE_ATTACHMENT, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_EXPANDABLE, + g_param_spec_boolean ( + "expandable", + "Expandable", + NULL, + TRUE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property ( + object_class, + PROP_EXPANDED, + g_param_spec_boolean ( + "expanded", + "Expanded", + NULL, + FALSE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property ( + object_class, + PROP_VIEW, + g_param_spec_object ( + "view", + "View", + NULL, + E_TYPE_ATTACHMENT_VIEW, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); +} + +static void +attachment_button_init (EAttachmentButton *button) +{ + GtkCellRenderer *renderer; + GtkCellLayout *cell_layout; + GtkTargetEntry *targets; + GtkTargetList *list; + GtkWidget *container; + GtkWidget *widget; + gint n_targets; + + button->priv = E_ATTACHMENT_BUTTON_GET_PRIVATE (button); + + /* Configure Widgets */ + + container = GTK_WIDGET (button); + + widget = gtk_button_new (); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + button->priv->expand_button = g_object_ref (widget); + gtk_widget_show (widget); + + e_mutual_binding_new ( + G_OBJECT (button), "expandable", + G_OBJECT (widget), "sensitive"); + + widget = gtk_toggle_button_new (); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + button->priv->toggle_button = g_object_ref (widget); + gtk_widget_show (widget); + + container = button->priv->expand_button; + + widget = gtk_cell_view_new (); + gtk_container_add (GTK_CONTAINER (container), widget); + button->priv->cell_view = g_object_ref (widget); + gtk_widget_show (widget); + + container = button->priv->toggle_button; + + widget = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); + gtk_container_add (GTK_CONTAINER (container), widget); + gtk_widget_show (widget); + + /* Configure Renderers */ + + cell_layout = GTK_CELL_LAYOUT (button->priv->cell_view); + + renderer = gtk_cell_renderer_pixbuf_new (); + g_object_set (renderer, "is-expander", TRUE, NULL); + gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); + + e_mutual_binding_new ( + G_OBJECT (button), "expanded", + G_OBJECT (renderer), "is-expanded"); + + renderer = gtk_cell_renderer_pixbuf_new (); + g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL); + gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); + + gtk_cell_layout_add_attribute ( + cell_layout, renderer, "gicon", + E_ATTACHMENT_STORE_COLUMN_ICON); + + /* Configure Drag and Drop */ + + list = gtk_target_list_new (NULL, 0); + gtk_target_list_add_uri_targets (list, 0); + targets = gtk_target_table_new_from_list (list, &n_targets); + + gtk_drag_source_set ( + button->priv->expand_button, GDK_BUTTON1_MASK, + targets, n_targets, GDK_ACTION_COPY); + + gtk_drag_source_set ( + button->priv->toggle_button, GDK_BUTTON1_MASK, + targets, n_targets, GDK_ACTION_COPY); + + gtk_target_table_free (targets, n_targets); + gtk_target_list_unref (list); + + /* Configure Signal Handlers */ + + g_signal_connect_swapped ( + button->priv->expand_button, "clicked", + G_CALLBACK (attachment_button_expand_clicked_cb), button); + + g_signal_connect_swapped ( + button->priv->expand_button, "drag-data-get", + G_CALLBACK (attachment_button_expand_drag_data_get_cb), + button); + + g_signal_connect_swapped ( + button->priv->toggle_button, "button-press-event", + G_CALLBACK (attachment_button_toggle_button_press_event_cb), + button); + + g_signal_connect_swapped ( + button->priv->toggle_button, "drag-data-get", + G_CALLBACK (attachment_button_expand_drag_data_get_cb), + button); + +} + +GType +e_attachment_button_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EAttachmentButtonClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) attachment_button_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EAttachmentButton), + 0, /* n_preallocs */ + (GInstanceInitFunc) attachment_button_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GTK_TYPE_HBOX, "EAttachmentButton", &type_info, 0); + } + + return type; +} + +GtkWidget * +e_attachment_button_new (EAttachmentView *view) +{ + g_return_val_if_fail (E_IS_ATTACHMENT_VIEW (view), NULL); + + return g_object_new ( + E_TYPE_ATTACHMENT_BUTTON, + "view", view, NULL); +} + +EAttachmentView * +e_attachment_button_get_view (EAttachmentButton *button) +{ + g_return_val_if_fail (E_IS_ATTACHMENT_BUTTON (button), NULL); + + return button->priv->view; +} + +EAttachment * +e_attachment_button_get_attachment (EAttachmentButton *button) +{ + g_return_val_if_fail (E_IS_ATTACHMENT_BUTTON (button), NULL); + + return button->priv->attachment; +} + +void +e_attachment_button_set_attachment (EAttachmentButton *button, + EAttachment *attachment) +{ + g_return_if_fail (E_IS_ATTACHMENT_BUTTON (button)); + + if (attachment != NULL) { + g_return_if_fail (E_IS_ATTACHMENT (attachment)); + g_object_ref (attachment); + } + + if (button->priv->attachment != NULL) { + g_signal_handler_disconnect ( + button->priv->attachment, + button->priv->reference_handler_id); + g_object_unref (button->priv->attachment); + } + + button->priv->attachment = attachment; + + if (attachment != NULL) { + gulong handler_id; + + handler_id = g_signal_connect_swapped ( + attachment, "notify::reference", + G_CALLBACK (attachment_button_update_cell_view), + button); + attachment_button_update_cell_view (button); + attachment_button_update_pixbufs (button); + button->priv->reference_handler_id = handler_id; + } + + g_object_notify (G_OBJECT (button), "attachment"); +} + +gboolean +e_attachment_button_get_expandable (EAttachmentButton *button) +{ + g_return_val_if_fail (E_IS_ATTACHMENT_BUTTON (button), FALSE); + + return button->priv->expandable; +} + +void +e_attachment_button_set_expandable (EAttachmentButton *button, + gboolean expandable) +{ + g_return_if_fail (E_IS_ATTACHMENT_BUTTON (button)); + + button->priv->expandable = expandable; + + if (!expandable) + e_attachment_button_set_expanded (button, FALSE); + + g_object_notify (G_OBJECT (button), "expandable"); +} + +gboolean +e_attachment_button_get_expanded (EAttachmentButton *button) +{ + g_return_val_if_fail (E_IS_ATTACHMENT_BUTTON (button), FALSE); + + return button->priv->expanded; +} + +void +e_attachment_button_set_expanded (EAttachmentButton *button, + gboolean expanded) +{ + g_return_if_fail (E_IS_ATTACHMENT_BUTTON (button)); + + button->priv->expanded = expanded; + + g_object_notify (G_OBJECT (button), "expanded"); +} diff --git a/widgets/misc/e-attachment-button.h b/widgets/misc/e-attachment-button.h new file mode 100644 index 0000000000..6e2f5672ef --- /dev/null +++ b/widgets/misc/e-attachment-button.h @@ -0,0 +1,83 @@ +/* + * e-attachment-button.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_ATTACHMENT_BUTTON_H +#define E_ATTACHMENT_BUTTON_H + +#include <gtk/gtk.h> +#include <widgets/misc/e-attachment.h> +#include <widgets/misc/e-attachment-view.h> + +/* Standard GObject macros */ +#define E_TYPE_ATTACHMENT_BUTTON \ + (e_attachment_button_get_type ()) +#define E_ATTACHMENT_BUTTON(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_ATTACHMENT_BUTTON, EAttachmentButton)) +#define E_ATTACHMENT_BUTTON_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_ATTACHMENT_BUTTON, EAttachmentButtonClass)) +#define E_IS_ATTACHMENT_BUTTON(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_ATTACHMENT_BUTTON)) +#define E_IS_ATTACHMENT_BUTTON_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_ATTACHMENT_BUTTON)) +#define E_ATTACHMENT_BUTTON_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_ATTACHMENT_BUTTON, EAttachmentButtonClass)) + +G_BEGIN_DECLS + +typedef struct _EAttachmentButton EAttachmentButton; +typedef struct _EAttachmentButtonClass EAttachmentButtonClass; +typedef struct _EAttachmentButtonPrivate EAttachmentButtonPrivate; + +struct _EAttachmentButton { + GtkHBox parent; + EAttachmentButtonPrivate *priv; +}; + +struct _EAttachmentButtonClass { + GtkHBoxClass parent_class; +}; + +GType e_attachment_button_get_type (void); +GtkWidget * e_attachment_button_new (EAttachmentView *view); +EAttachmentView * + e_attachment_button_get_view (EAttachmentButton *button); +EAttachment * e_attachment_button_get_attachment + (EAttachmentButton *button); +void e_attachment_button_set_attachment + (EAttachmentButton *button, + EAttachment *attachment); +gboolean e_attachment_button_get_expandable + (EAttachmentButton *button); +void e_attachment_button_set_expandable + (EAttachmentButton *button, + gboolean expandable); +gboolean e_attachment_button_get_expanded(EAttachmentButton *button); +void e_attachment_button_set_expanded(EAttachmentButton *button, + gboolean expanded); + +G_END_DECLS + +#endif /* E_ATTACHMENT_BUTTON_H */ diff --git a/widgets/misc/e-attachment-icon-view.c b/widgets/misc/e-attachment-icon-view.c index e8a7db8459..0845f82a76 100644 --- a/widgets/misc/e-attachment-icon-view.c +++ b/widgets/misc/e-attachment-icon-view.c @@ -222,7 +222,7 @@ attachment_icon_view_popup_menu (GtkWidget *widget) { EAttachmentView *view = E_ATTACHMENT_VIEW (widget); - e_attachment_view_show_popup_menu (view, NULL); + e_attachment_view_show_popup_menu (view, NULL, NULL, NULL); return TRUE; } diff --git a/widgets/misc/e-attachment-paned.c b/widgets/misc/e-attachment-paned.c index f9f7bb1cca..9502f41296 100644 --- a/widgets/misc/e-attachment-paned.c +++ b/widgets/misc/e-attachment-paned.c @@ -409,6 +409,17 @@ attachment_paned_unselect_all (EAttachmentView *view) } static void +attachment_paned_update_actions (EAttachmentView *view) +{ + EAttachmentPanedPrivate *priv; + + priv = E_ATTACHMENT_PANED_GET_PRIVATE (view); + view = E_ATTACHMENT_VIEW (priv->icon_view); + + e_attachment_view_update_actions (view); +} + +static void attachment_paned_class_init (EAttachmentPanedClass *class) { GObjectClass *object_class; @@ -462,6 +473,7 @@ attachment_paned_iface_init (EAttachmentViewIface *iface) iface->unselect_path = attachment_paned_unselect_path; iface->select_all = attachment_paned_select_all; iface->unselect_all = attachment_paned_unselect_all; + iface->update_actions = attachment_paned_update_actions; } static void diff --git a/widgets/misc/e-attachment-store.c b/widgets/misc/e-attachment-store.c index 589f670f34..24cc89b366 100644 --- a/widgets/misc/e-attachment-store.c +++ b/widgets/misc/e-attachment-store.c @@ -715,6 +715,7 @@ attachment_store_get_uris_save_cb (EAttachment *attachment, g_list_foreach ( uri_context->attachment_list, (GFunc) e_attachment_cancel, NULL); + error = NULL; /* Otherwise, we can only report back one error. So if * this is something other than cancellation, dump it to @@ -722,9 +723,10 @@ attachment_store_get_uris_save_cb (EAttachment *attachment, } else if (!g_error_matches ( error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("%s", error->message); + } + if (error != NULL) g_error_free (error); - } /* If there's still jobs running, let them finish. */ if (uri_context->attachment_list != NULL) @@ -846,9 +848,8 @@ e_attachment_store_get_uris_finish (EAttachmentStore *store, GSimpleAsyncResult *simple; gchar **uris; - g_return_val_if_fail ( - g_simple_async_result_is_valid (result, G_OBJECT (store), - e_attachment_store_get_uris_async), FALSE); + g_return_val_if_fail (E_IS_ATTACHMENT_STORE (store), NULL); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL); simple = G_SIMPLE_ASYNC_RESULT (result); uris = g_simple_async_result_get_op_res_gpointer (simple); diff --git a/widgets/misc/e-attachment-tree-view.c b/widgets/misc/e-attachment-tree-view.c index 336b3225df..f8a74d293f 100644 --- a/widgets/misc/e-attachment-tree-view.c +++ b/widgets/misc/e-attachment-tree-view.c @@ -240,7 +240,7 @@ attachment_tree_view_popup_menu (GtkWidget *widget) { EAttachmentView *view = E_ATTACHMENT_VIEW (widget); - e_attachment_view_show_popup_menu (view, NULL); + e_attachment_view_show_popup_menu (view, NULL, NULL, NULL); return TRUE; } diff --git a/widgets/misc/e-attachment-view.c b/widgets/misc/e-attachment-view.c index d6dff653cc..5c7acd4561 100644 --- a/widgets/misc/e-attachment-view.c +++ b/widgets/misc/e-attachment-view.c @@ -1059,7 +1059,8 @@ e_attachment_view_button_press_event (EAttachmentView *view, * popup menu when right-clicking on an attachment, * but editable views can show the menu any time. */ if (item_clicked || editable) { - e_attachment_view_show_popup_menu (view, event); + e_attachment_view_show_popup_menu ( + view, event, NULL, NULL); return TRUE; } } @@ -1468,6 +1469,21 @@ e_attachment_view_get_action_group (EAttachmentView *view, return e_lookup_action_group (ui_manager, group_name); } +GtkWidget * +e_attachment_view_get_popup_menu (EAttachmentView *view) +{ + GtkUIManager *ui_manager; + GtkWidget *menu; + + g_return_val_if_fail (E_IS_ATTACHMENT_VIEW (view), NULL); + + ui_manager = e_attachment_view_get_ui_manager (view); + menu = gtk_ui_manager_get_widget (ui_manager, "/context"); + g_return_val_if_fail (GTK_IS_MENU (menu), NULL); + + return menu; +} + GtkUIManager * e_attachment_view_get_ui_manager (EAttachmentView *view) { @@ -1511,27 +1527,26 @@ e_attachment_view_recent_action_new (EAttachmentView *view, void e_attachment_view_show_popup_menu (EAttachmentView *view, - GdkEventButton *event) + GdkEventButton *event, + GtkMenuPositionFunc func, + gpointer user_data) { - GtkUIManager *ui_manager; GtkWidget *menu; g_return_if_fail (E_IS_ATTACHMENT_VIEW (view)); e_attachment_view_update_actions (view); - ui_manager = e_attachment_view_get_ui_manager (view); - menu = gtk_ui_manager_get_widget (ui_manager, "/context"); - g_return_if_fail (GTK_IS_MENU (menu)); + menu = e_attachment_view_get_popup_menu (view); if (event != NULL) gtk_menu_popup ( - GTK_MENU (menu), NULL, NULL, NULL, NULL, - event->button, event->time); + GTK_MENU (menu), NULL, NULL, func, + user_data, event->button, event->time); else gtk_menu_popup ( - GTK_MENU (menu), NULL, NULL, NULL, NULL, - 0, gtk_get_current_event_time ()); + GTK_MENU (menu), NULL, NULL, func, + user_data, 0, gtk_get_current_event_time ()); } void diff --git a/widgets/misc/e-attachment-view.h b/widgets/misc/e-attachment-view.h index 8b625d0d8a..8285928c5b 100644 --- a/widgets/misc/e-attachment-view.h +++ b/widgets/misc/e-attachment-view.h @@ -209,6 +209,7 @@ GtkAction * e_attachment_view_get_action (EAttachmentView *view, GtkActionGroup *e_attachment_view_get_action_group (EAttachmentView *view, const gchar *group_name); +GtkWidget * e_attachment_view_get_popup_menu(EAttachmentView *view); GtkUIManager * e_attachment_view_get_ui_manager(EAttachmentView *view); GtkAction * e_attachment_view_recent_action_new (EAttachmentView *view, @@ -216,7 +217,9 @@ GtkAction * e_attachment_view_recent_action_new const gchar *action_label); void e_attachment_view_show_popup_menu (EAttachmentView *view, - GdkEventButton *event); + GdkEventButton *event, + GtkMenuPositionFunc func, + gpointer user_data); void e_attachment_view_update_actions(EAttachmentView *view); G_END_DECLS diff --git a/widgets/misc/e-attachment.c b/widgets/misc/e-attachment.c index bd9795c908..16bd9fd26c 100644 --- a/widgets/misc/e-attachment.c +++ b/widgets/misc/e-attachment.c @@ -1694,9 +1694,8 @@ e_attachment_load_finish (EAttachment *attachment, GSimpleAsyncResult *simple; CamelMimePart *mime_part; - g_return_val_if_fail ( - g_simple_async_result_is_valid (result, - G_OBJECT (attachment), e_attachment_load_async), FALSE); + g_return_val_if_fail (E_IS_ATTACHMENT (attachment), FALSE); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); simple = G_SIMPLE_ASYNC_RESULT (result); mime_part = g_simple_async_result_get_op_res_gpointer (simple); @@ -1990,9 +1989,8 @@ e_attachment_open_finish (EAttachment *attachment, GSimpleAsyncResult *simple; gboolean success; - g_return_val_if_fail ( - g_simple_async_result_is_valid (result, - G_OBJECT (attachment), e_attachment_open_async), FALSE); + g_return_val_if_fail (E_IS_ATTACHMENT (attachment), FALSE); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); simple = G_SIMPLE_ASYNC_RESULT (result); success = g_simple_async_result_get_op_res_gboolean (simple); @@ -2500,9 +2498,8 @@ e_attachment_save_finish (EAttachment *attachment, GSimpleAsyncResult *simple; GFile *destination; - g_return_val_if_fail ( - g_simple_async_result_is_valid (result, - G_OBJECT (attachment), e_attachment_save_async), FALSE); + g_return_val_if_fail (E_IS_ATTACHMENT (attachment), FALSE); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); simple = G_SIMPLE_ASYNC_RESULT (result); destination = g_simple_async_result_get_op_res_gpointer (simple); diff --git a/widgets/misc/e-menu-button.c b/widgets/misc/e-menu-button.c new file mode 100644 index 0000000000..af60790bc5 --- /dev/null +++ b/widgets/misc/e-menu-button.c @@ -0,0 +1,497 @@ +/* + * e-menu-button.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-menu-button.h" + +#define E_MENU_BUTTON_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_MENU_BUTTON, EMenuButtonPrivate)) + +struct _EMenuButtonPrivate { + GtkWidget *toggle_button; + GtkMenu *menu; /* not referenced */ +}; + +enum { + PROP_0, + PROP_MENU +}; + +enum { + SHOW_MENU, + LAST_SIGNAL +}; + +static gpointer parent_class; +static gulong signals[LAST_SIGNAL]; + +static void +menu_button_detach (GtkWidget *widget, + GtkMenu *menu) +{ + EMenuButtonPrivate *priv; + + priv = E_MENU_BUTTON_GET_PRIVATE (widget); + + g_return_if_fail (priv->menu == menu); + + priv->menu = NULL; +} + +static void +menu_button_deactivate_cb (EMenuButton *menu_button) +{ + GtkToggleButton *toggle_button; + + toggle_button = GTK_TOGGLE_BUTTON (menu_button->priv->toggle_button); + gtk_toggle_button_set_active (toggle_button, FALSE); +} + +static void +menu_button_menu_position (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, + EMenuButton *menu_button) +{ + GtkRequisition requisition; + GtkTextDirection direction; + GdkRectangle monitor; + GdkScreen *screen; + GdkWindow *window; + GtkWidget *widget; + GtkWidget *toggle_button; + gint button_bottom; + gint monitor_bottom; + gint monitor_num; + + widget = GTK_WIDGET (menu_button); + toggle_button = menu_button->priv->toggle_button; + gtk_widget_size_request (GTK_WIDGET (menu), &requisition); + + window = gtk_widget_get_parent_window (widget); + screen = gtk_widget_get_screen (GTK_WIDGET (menu)); + monitor_num = gdk_screen_get_monitor_at_window (screen, window); + if (monitor_num < 0) + monitor_num = 0; + gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); + + gdk_window_get_origin (window, x, y); + *x += widget->allocation.x; + *y += widget->allocation.y; + + direction = gtk_widget_get_direction (widget); + if (direction == GTK_TEXT_DIR_LTR) + x += MAX (widget->allocation.width - requisition.width, 0); + else if (requisition.width > widget->allocation.width) + x -= requisition.width - widget->allocation.width; + + button_bottom = *y + toggle_button->allocation.height; + monitor_bottom = monitor.y + monitor.height; + + if (button_bottom + requisition.height <= monitor_bottom) + y += toggle_button->allocation.height; + else if (*y - requisition.height >= monitor.y) + y -= requisition.height; + else if (monitor_bottom - button_bottom > *y) + y += toggle_button->allocation.height; + else + y -= requisition.height; + + *push_in = FALSE; +} + +static void +menu_button_show_popup_menu (EMenuButton *menu_button, + GdkEventButton *event) +{ + g_signal_emit (menu_button, signals[SHOW_MENU], 0); + + if (menu_button->priv->menu == NULL) + return; + + if (event != NULL) + gtk_menu_popup ( + menu_button->priv->menu, NULL, NULL, + (GtkMenuPositionFunc) menu_button_menu_position, + menu_button, event->button, event->time); + else + gtk_menu_popup ( + menu_button->priv->menu, NULL, NULL, + (GtkMenuPositionFunc) menu_button_menu_position, + menu_button, 0, gtk_get_current_event_time ()); +} + +static gboolean +menu_button_toggle_button_press_event_cb (EMenuButton *menu_button, + GdkEventButton *event) +{ + if (event->button == 1) { + menu_button_show_popup_menu (menu_button, event); + return TRUE; + } + + return FALSE; +} + +static void +menu_button_toggle_toggled_cb (EMenuButton *menu_button) +{ + GtkMenuShell *menu_shell; + GtkToggleButton *toggle_button; + + menu_shell = GTK_MENU_SHELL (menu_button->priv->menu); + toggle_button = GTK_TOGGLE_BUTTON (menu_button->priv->toggle_button); + + if (!gtk_toggle_button_get_active (toggle_button)) + return; + + if (GTK_WIDGET_VISIBLE (menu_shell)) + return; + + /* We get here only when the menu is activated by a key + * press, so that we can select the first menu item. */ + menu_button_show_popup_menu (menu_button, NULL); + gtk_menu_shell_select_first (menu_shell, FALSE); +} + +static void +menu_button_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_MENU: + e_menu_button_set_menu ( + E_MENU_BUTTON (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +menu_button_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_MENU: + g_value_set_object ( + value, e_menu_button_get_menu ( + E_MENU_BUTTON (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +menu_button_dispose (GObject *object) +{ + EMenuButtonPrivate *priv; + + priv = E_MENU_BUTTON_GET_PRIVATE (object); + + if (priv->toggle_button != NULL) { + g_object_unref (priv->toggle_button); + priv->toggle_button = NULL; + } + + if (priv->menu != NULL) { + g_signal_handlers_disconnect_by_func ( + priv->menu, menu_button_deactivate_cb, object); + gtk_menu_detach (priv->menu); + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +menu_button_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + EMenuButtonPrivate *priv; + GtkRequisition child_requisition; + GtkWidget *child; + + priv = E_MENU_BUTTON_GET_PRIVATE (widget); + + /* Chain up to parent's size_request() method. */ + GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition); + + child = priv->toggle_button; + gtk_widget_size_request (child, &child_requisition); + requisition->width += child_requisition.width; +} + +static void +menu_button_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + EMenuButtonPrivate *priv; + GtkAllocation child_allocation; + GtkRequisition child_requisition; + GtkWidget *child; + gint toggle_x; + + priv = E_MENU_BUTTON_GET_PRIVATE (widget); + + widget->allocation = *allocation; + + child = priv->toggle_button; + gtk_widget_size_request (child, &child_requisition); + + toggle_x = allocation->x + allocation->width - child_requisition.width; + + child_allocation.x = allocation->x; + child_allocation.y = allocation->y; + child_allocation.width = toggle_x - allocation->x; + child_allocation.height = allocation->height; + + /* Chain up to parent's size_allocate() method. */ + GTK_WIDGET_CLASS (parent_class)-> + size_allocate (widget, &child_allocation); + + child_allocation.x = toggle_x; + child_allocation.y = allocation->y; + child_allocation.width = child_requisition.width; + child_allocation.height = allocation->height; + + gtk_widget_size_allocate (child, &child_allocation); +} + +static void +menu_button_state_changed (GtkWidget *widget, + GtkStateType previous_state) +{ + EMenuButtonPrivate *priv; + + priv = E_MENU_BUTTON_GET_PRIVATE (widget); + + if (!GTK_WIDGET_IS_SENSITIVE (widget) && priv->menu != NULL) + gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu)); + + /* Chain up to parent's state_changed() method. */ + GTK_WIDGET_CLASS (parent_class)-> + state_changed (widget, previous_state); +} + +static void +menu_button_remove (GtkContainer *container, + GtkWidget *widget) +{ + EMenuButtonPrivate *priv; + + priv = E_MENU_BUTTON_GET_PRIVATE (container); + + /* Look in the internal widgets first. */ + + if (widget == priv->toggle_button) { + gtk_widget_unparent (priv->toggle_button); + gtk_widget_queue_resize (GTK_WIDGET (container)); + return; + } + + /* Chain up to parent's remove() method. */ + GTK_CONTAINER_CLASS (parent_class)->remove (container, widget); +} + +static void +menu_button_forall (GtkContainer *container, + gboolean include_internals, + GtkCallback callback, + gpointer callback_data) +{ + EMenuButtonPrivate *priv; + + priv = E_MENU_BUTTON_GET_PRIVATE (container); + + if (include_internals) + callback (priv->toggle_button, callback_data); + + /* Chain up to parent's forall() method. */ + GTK_CONTAINER_CLASS (parent_class)->forall ( + container, include_internals, callback, callback_data); +} + +static void +menu_button_class_init (EMenuButtonClass *class) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class; + GtkContainerClass *container_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EMenuButtonPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = menu_button_set_property; + object_class->get_property = menu_button_get_property; + object_class->dispose = menu_button_dispose; + + widget_class = GTK_WIDGET_CLASS (class); + widget_class->size_request = menu_button_size_request; + widget_class->size_allocate = menu_button_size_allocate; + widget_class->state_changed = menu_button_state_changed; + + container_class = GTK_CONTAINER_CLASS (class); + container_class->remove = menu_button_remove; + container_class->forall = menu_button_forall; + + g_object_class_install_property ( + object_class, + PROP_MENU, + g_param_spec_object ( + "menu", + "Menu", + NULL, + GTK_TYPE_MENU, + G_PARAM_READWRITE)); + + signals[SHOW_MENU] = g_signal_new ( + "show-menu", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EMenuButtonClass, show_menu), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + +static void +menu_button_init (EMenuButton *menu_button) +{ + GtkWidget *container; + GtkWidget *widget; + + menu_button->priv = E_MENU_BUTTON_GET_PRIVATE (menu_button); + + container = GTK_WIDGET (menu_button); + + widget = gtk_toggle_button_new (); + gtk_widget_set_sensitive (widget, FALSE); + gtk_widget_set_parent (widget, container); + menu_button->priv->toggle_button = g_object_ref (widget); + gtk_widget_show (widget); + + container = widget; + + widget = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); + gtk_container_add (GTK_CONTAINER (container), widget); + gtk_widget_show (widget); + + g_signal_connect_swapped ( + menu_button->priv->toggle_button, "button-press-event", + G_CALLBACK (menu_button_toggle_button_press_event_cb), + menu_button); + + g_signal_connect_swapped ( + menu_button->priv->toggle_button, "toggled", + G_CALLBACK (menu_button_toggle_toggled_cb), menu_button); +} + +GType +e_menu_button_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EMenuButtonClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) menu_button_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_init */ + sizeof (EMenuButton), + 0, /* n_preallocs */ + (GInstanceInitFunc) menu_button_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GTK_TYPE_BUTTON, "EMenuButton", &type_info, 0); + } + + return type; +} + +GtkWidget * +e_menu_button_new (void) +{ + return g_object_new (E_TYPE_MENU_BUTTON, NULL); +} + +GtkWidget * +e_menu_button_get_menu (EMenuButton *menu_button) +{ + g_return_val_if_fail (E_IS_MENU_BUTTON (menu_button), NULL); + + return GTK_WIDGET (menu_button->priv->menu); +} + +void +e_menu_button_set_menu (EMenuButton *menu_button, + GtkWidget *menu) +{ + g_return_if_fail (E_IS_MENU_BUTTON (menu_button)); + g_return_if_fail (GTK_IS_MENU (menu) || menu == NULL); + + if (menu_button->priv->menu == GTK_MENU (menu)) + goto exit; + + if (menu_button->priv->menu != NULL) { + GtkMenuShell *menu_shell; + + menu_shell = GTK_MENU_SHELL (menu_button->priv->menu); + + if (GTK_WIDGET_VISIBLE (menu_shell)) + gtk_menu_shell_deactivate (menu_shell); + + g_signal_handlers_disconnect_by_func ( + menu_shell, menu_button_deactivate_cb, menu_button); + + gtk_menu_detach (menu_button->priv->menu); + } + + menu_button->priv->menu = GTK_MENU (menu); + + if (menu != NULL) { + gtk_menu_attach_to_widget ( + GTK_MENU (menu), GTK_WIDGET (menu_button), + (GtkMenuDetachFunc) menu_button_detach); + + g_signal_connect_swapped ( + menu, "deactivate", + G_CALLBACK (menu_button_deactivate_cb), menu_button); + } + + gtk_widget_set_sensitive ( + menu_button->priv->toggle_button, menu != NULL); + +exit: + g_object_notify (G_OBJECT (menu_button), "menu"); +} diff --git a/widgets/misc/e-menu-button.h b/widgets/misc/e-menu-button.h new file mode 100644 index 0000000000..fa27a77c67 --- /dev/null +++ b/widgets/misc/e-menu-button.h @@ -0,0 +1,74 @@ +/* + * e-menu-button.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) + * + */ + +/* This is like a GtkMenuToolButton, expect not a GtkToolItem. */ + +#ifndef E_MENU_BUTTON_H +#define E_MENU_BUTTON_H + +#include <gtk/gtk.h> + +/* Standard GObject macros */ +#define E_TYPE_MENU_BUTTON \ + (e_menu_button_get_type ()) +#define E_MENU_BUTTON(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_MENU_BUTTON, EMenuButton)) +#define E_MENU_BUTTON_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_MENU_BUTTON, EMenuButtonClass)) +#define E_IS_MENU_BUTTON(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_MENU_BUTTON)) +#define E_IS_MENU_BUTTON_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_MENU_BUTTON)) +#define E_MENU_BUTTON_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_MENU_BUTTON, EMenuButtonClass)) + +G_BEGIN_DECLS + +typedef struct _EMenuButton EMenuButton; +typedef struct _EMenuButtonClass EMenuButtonClass; +typedef struct _EMenuButtonPrivate EMenuButtonPrivate; + +struct _EMenuButton { + GtkButton parent; + EMenuButtonPrivate *priv; +}; + +struct _EMenuButtonClass { + GtkButtonClass parent_class; + + /* Signals */ + void (*show_menu) (EMenuButton *menu_button); +}; + +GType e_menu_button_get_type (void); +GtkWidget * e_menu_button_new (void); +GtkWidget * e_menu_button_get_menu (EMenuButton *menu_button); +void e_menu_button_set_menu (EMenuButton *menu_button, + GtkWidget *menu); + +G_END_DECLS + +#endif /* E_MENU_BUTTON_H */ |