evolution r37504 - in branches/kill-bonobo: addressbook/gui/contact-editor calendar/gui mail widgets/misc
- From: mbarnes svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution r37504 - in branches/kill-bonobo: addressbook/gui/contact-editor calendar/gui mail widgets/misc
- Date: Tue, 7 Apr 2009 21:40:49 +0000 (UTC)
Author: mbarnes
Date: Tue Apr 7 21:40:49 2009
New Revision: 37504
URL: http://svn.gnome.org/viewvc/evolution?rev=37504&view=rev
Log:
Attachment rewrite pretty much complete. Just testing now.
Added:
branches/kill-bonobo/widgets/misc/e-attachment-button.c
branches/kill-bonobo/widgets/misc/e-attachment-button.h
branches/kill-bonobo/widgets/misc/e-menu-button.c
branches/kill-bonobo/widgets/misc/e-menu-button.h
Removed:
branches/kill-bonobo/mail/e-mail-attachment-button.c
branches/kill-bonobo/mail/e-mail-attachment-button.h
Modified:
branches/kill-bonobo/addressbook/gui/contact-editor/e-contact-editor.c
branches/kill-bonobo/calendar/gui/e-meeting-time-sel.c
branches/kill-bonobo/mail/Makefile.am
branches/kill-bonobo/mail/e-mail-attachment-bar.c
branches/kill-bonobo/mail/em-format-html-display.c
branches/kill-bonobo/widgets/misc/Makefile.am
branches/kill-bonobo/widgets/misc/e-attachment-icon-view.c
branches/kill-bonobo/widgets/misc/e-attachment-paned.c
branches/kill-bonobo/widgets/misc/e-attachment-store.c
branches/kill-bonobo/widgets/misc/e-attachment-tree-view.c
branches/kill-bonobo/widgets/misc/e-attachment-view.c
branches/kill-bonobo/widgets/misc/e-attachment-view.h
branches/kill-bonobo/widgets/misc/e-attachment.c
Modified: branches/kill-bonobo/addressbook/gui/contact-editor/e-contact-editor.c
==============================================================================
--- branches/kill-bonobo/addressbook/gui/contact-editor/e-contact-editor.c (original)
+++ branches/kill-bonobo/addressbook/gui/contact-editor/e-contact-editor.c Tue Apr 7 21:40:49 2009
@@ -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>
Modified: branches/kill-bonobo/calendar/gui/e-meeting-time-sel.c
==============================================================================
--- branches/kill-bonobo/calendar/gui/e-meeting-time-sel.c (original)
+++ branches/kill-bonobo/calendar/gui/e-meeting-time-sel.c Tue Apr 7 21:40:49 2009
@@ -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"
Modified: branches/kill-bonobo/mail/Makefile.am
==============================================================================
--- branches/kill-bonobo/mail/Makefile.am (original)
+++ branches/kill-bonobo/mail/Makefile.am Tue Apr 7 21:40:49 2009
@@ -39,8 +39,6 @@
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 \
Modified: branches/kill-bonobo/mail/e-mail-attachment-bar.c
==============================================================================
--- branches/kill-bonobo/mail/e-mail-attachment-bar.c (original)
+++ branches/kill-bonobo/mail/e-mail-attachment-bar.c Tue Apr 7 21:40:49 2009
@@ -420,6 +420,17 @@
}
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 @@
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
Modified: branches/kill-bonobo/mail/em-format-html-display.c
==============================================================================
--- branches/kill-bonobo/mail/em-format-html-display.c (original)
+++ branches/kill-bonobo/mail/em-format-html-display.c Tue Apr 7 21:40:49 2009
@@ -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 @@
}
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 @@
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 @@
return TRUE;
}
-/* not used currently */
-/* frame source callback */
static void
efhd_attachment_frame (EMFormat *emf,
CamelStream *stream,
Modified: branches/kill-bonobo/widgets/misc/Makefile.am
==============================================================================
--- branches/kill-bonobo/widgets/misc/Makefile.am (original)
+++ branches/kill-bonobo/widgets/misc/Makefile.am Tue Apr 7 21:40:49 2009
@@ -40,6 +40,7 @@
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 @@
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 @@
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 @@
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 \
Added: branches/kill-bonobo/widgets/misc/e-attachment-button.c
==============================================================================
--- (empty file)
+++ branches/kill-bonobo/widgets/misc/e-attachment-button.c Tue Apr 7 21:40:49 2009
@@ -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");
+}
Added: branches/kill-bonobo/widgets/misc/e-attachment-button.h
==============================================================================
--- (empty file)
+++ branches/kill-bonobo/widgets/misc/e-attachment-button.h Tue Apr 7 21:40:49 2009
@@ -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 */
Modified: branches/kill-bonobo/widgets/misc/e-attachment-icon-view.c
==============================================================================
--- branches/kill-bonobo/widgets/misc/e-attachment-icon-view.c (original)
+++ branches/kill-bonobo/widgets/misc/e-attachment-icon-view.c Tue Apr 7 21:40:49 2009
@@ -222,7 +222,7 @@
{
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;
}
Modified: branches/kill-bonobo/widgets/misc/e-attachment-paned.c
==============================================================================
--- branches/kill-bonobo/widgets/misc/e-attachment-paned.c (original)
+++ branches/kill-bonobo/widgets/misc/e-attachment-paned.c Tue Apr 7 21:40:49 2009
@@ -409,6 +409,17 @@
}
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 @@
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
Modified: branches/kill-bonobo/widgets/misc/e-attachment-store.c
==============================================================================
--- branches/kill-bonobo/widgets/misc/e-attachment-store.c (original)
+++ branches/kill-bonobo/widgets/misc/e-attachment-store.c Tue Apr 7 21:40:49 2009
@@ -715,6 +715,7 @@
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 @@
} 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 @@
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);
Modified: branches/kill-bonobo/widgets/misc/e-attachment-tree-view.c
==============================================================================
--- branches/kill-bonobo/widgets/misc/e-attachment-tree-view.c (original)
+++ branches/kill-bonobo/widgets/misc/e-attachment-tree-view.c Tue Apr 7 21:40:49 2009
@@ -240,7 +240,7 @@
{
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;
}
Modified: branches/kill-bonobo/widgets/misc/e-attachment-view.c
==============================================================================
--- branches/kill-bonobo/widgets/misc/e-attachment-view.c (original)
+++ branches/kill-bonobo/widgets/misc/e-attachment-view.c Tue Apr 7 21:40:49 2009
@@ -1059,7 +1059,8 @@
* 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 @@
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 @@
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
Modified: branches/kill-bonobo/widgets/misc/e-attachment-view.h
==============================================================================
--- branches/kill-bonobo/widgets/misc/e-attachment-view.h (original)
+++ branches/kill-bonobo/widgets/misc/e-attachment-view.h Tue Apr 7 21:40:49 2009
@@ -209,6 +209,7 @@
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 @@
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
Modified: branches/kill-bonobo/widgets/misc/e-attachment.c
==============================================================================
--- branches/kill-bonobo/widgets/misc/e-attachment.c (original)
+++ branches/kill-bonobo/widgets/misc/e-attachment.c Tue Apr 7 21:40:49 2009
@@ -1694,9 +1694,8 @@
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 @@
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 @@
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);
Added: branches/kill-bonobo/widgets/misc/e-menu-button.c
==============================================================================
--- (empty file)
+++ branches/kill-bonobo/widgets/misc/e-menu-button.c Tue Apr 7 21:40:49 2009
@@ -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");
+}
Added: branches/kill-bonobo/widgets/misc/e-menu-button.h
==============================================================================
--- (empty file)
+++ branches/kill-bonobo/widgets/misc/e-menu-button.h Tue Apr 7 21:40:49 2009
@@ -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 */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]