/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifdef HAVE_CONFIG_H
# include "config.h"
+#include "claws-features.h"
#endif
#include <glib.h>
#include "menu.h"
#include "utils.h"
#include "gtkutils.h"
-
-#ifdef MAEMO
-#ifdef CHINOOK
-#include <hildon/hildon-program.h>
-#else
-#include <hildon-widgets/hildon-program.h>
-#endif
-#include <gtk/gtkmain.h>
-#endif
-
-static void connect_accel_change_signals(GtkWidget* widget, GtkWidget *wid2) ;
-
+#include "defs.h"
GtkActionGroup *cm_menu_create_action_group(const gchar *name, GtkActionEntry *entries,
gint num_entries, gpointer data)
g_free(path);
}
-void cm_menu_set_sensitive_full(GtkUIManager *gui_manager, gchar *menu, gboolean sensitive)
+void cm_menu_set_sensitive_full(GtkUIManager *gui_manager, const gchar *menu, gboolean sensitive)
{
GtkWidget *widget;
gchar *path = g_strdup_printf("/%s/", menu);
}
gtk_widget_set_sensitive(widget, sensitive);
+
+ if (strcmp(menu, "Menus/SummaryViewPopup/Reedit") == 0)
+ (sensitive)? gtk_widget_show(widget) : gtk_widget_hide(widget);
+
+ g_free(path);
+}
+
+gchar *cm_menu_item_get_shortcut(GtkUIManager *gui_manager, gchar *menu)
+{
+ GtkWidget *widget;
+ gchar *path = g_strdup_printf("/%s/", menu);
+ const gchar *accel = NULL;
+ GtkAccelKey key;
+
+ widget = gtk_ui_manager_get_widget(gui_manager, path);
+ if( !GTK_IS_WIDGET(widget) ) {
+ g_message("Blah, '%s' is not a widget.\n", path);
+ }
+
+ if( !GTK_IS_MENU_ITEM(widget) ) {
+ g_message("Blah, '%s' is not a menu item.\n", path);
+ }
+
g_free(path);
+
+ accel = gtk_menu_item_get_accel_path(GTK_MENU_ITEM(widget));
+
+ if (accel && gtk_accel_map_lookup_entry(accel, &key))
+ return gtk_accelerator_get_label (key.accel_key, key.accel_mods);
+ else
+ return g_strdup(_("None"));
+
+}
+
+GtkWidget *cm_menu_item_new_label_from_url(gchar *url)
+{
+ gint len = strlen(url);
+ if (len > MAX_MENU_LABEL_LENGTH) {
+ g_message("Refusing a %d bytes string as menu label\n", len);
+ url[64] = '\0', url[63] = url[62] = url[61] = '.', url[60] = ' ';
+ GtkWidget *newlabel = gtk_menu_item_new_with_label(url);
+ gtk_widget_set_tooltip_markup(GTK_WIDGET(newlabel),
+ g_strconcat("<span><b>", _("Warning:"), "</b>",
+ _("This URL was too long for displaying and\n"
+ "has been truncated for safety. This message could be\n"
+ "corrupted, malformed or part of some DoS attempt."),
+ "</span>", NULL));
+ return newlabel;
+ }
+
+ return gtk_menu_item_new_with_label(url);
}
void cm_toggle_menu_set_active_full(GtkUIManager *gui_manager, gchar *menu, gboolean active)
void menu_set_sensitive_all(GtkMenuShell *menu_shell, gboolean sensitive)
{
+ GList *children = gtk_container_get_children(GTK_CONTAINER(menu_shell));
GList *cur;
- for (cur = menu_shell->children; cur != NULL; cur = cur->next)
+ for (cur = children; cur != NULL; cur = cur->next)
gtk_widget_set_sensitive(GTK_WIDGET(cur->data), sensitive);
+
+ g_list_free(children);
}
void menu_button_position(GtkMenu *menu, gint *x, gint *y, gboolean *push_in,
GtkWidget *widget;
gint wheight;
gint wx, wy;
- GtkRequisition mreq;
+ GtkAllocation allocation;
+ GtkRequisition mreq, wreq;
GdkScreen *screen;
GdkRectangle monitor;
gint monitor_num;
- g_return_if_fail(x && y);
- g_return_if_fail(GTK_IS_BUTTON(user_data));
+ cm_return_if_fail(x && y);
+ cm_return_if_fail(GTK_IS_BUTTON(user_data));
widget = GTK_WIDGET(user_data);
- gdk_window_get_origin(widget->window, x, y);
- wheight = widget->requisition.height;
- wx = widget->allocation.x;
- wy = widget->allocation.y;
+ gdk_window_get_origin(gtk_widget_get_window(widget), x, y);
+ gtk_widget_get_requisition(widget, &wreq);
+ wheight = wreq.height;
+ gtk_widget_get_allocation(widget, &allocation);
+ wx = allocation.x;
+ wy = allocation.y;
gtk_widget_size_request(GTK_WIDGET(menu), &mreq);
screen = gtk_widget_get_screen (widget);
GtkWidget *menu;
GtkWidget *menuitem;
gpointer menu_data;
+ GList *children;
GList *cur;
- gint n;
+ gint n, found = -1;
menu = gtk_cmoption_menu_get_menu(optmenu);
+ children = gtk_container_get_children(GTK_CONTAINER(GTK_MENU_SHELL(menu)));
- for (cur = GTK_MENU_SHELL(menu)->children, n = 0;
+ for (cur = children, n = 0;
cur != NULL; cur = cur->next, n++) {
menuitem = GTK_WIDGET(cur->data);
menu_data = g_object_get_data(G_OBJECT(menuitem),
MENU_VAL_ID);
if (func) {
- if (func(menu_data, data) == 0)
- return n;
- } else if (menu_data == data)
- return n;
+ if (func(menu_data, data) == 0) {
+ found = n;
+ break;
+ }
+ } else if (menu_data == data) {
+ found = n;
+ break;
+ }
}
- return -1;
-}
+ g_list_free(children);
-static void connect_accel_change_signals(GtkWidget* widget, GtkWidget *wid2)
-{
-#if 0
- g_signal_connect_after(G_OBJECT(widget), "add_accelerator",
- G_CALLBACK(menu_item_add_accel), wid2);
- g_signal_connect_after(G_OBJECT(widget), "remove_accelerator",
- G_CALLBACK(menu_item_remove_accel), wid2);
-#endif
-}
-
-void menu_connect_identical_items(void)
-{
-#if 0 /* DEPRECATED */
- gint n;
- GtkWidget *item1;
- GtkWidget *item2;
-
- static const struct {
- const gchar *path1;
- const gchar *path2;
- } pairs[] = {
- {"<Main>/Message/Reply", "<SummaryView>/Reply"},
-#ifndef GENERIC_UMPC
- {"<Main>/Message/Reply to/all", "<SummaryView>/Reply to/all"},
- {"<Main>/Message/Reply to/sender", "<SummaryView>/Reply to/sender"},
- {"<Main>/Message/Reply to/mailing list", "<SummaryView>/Reply to/mailing list"},
-#endif
- {"<Main>/Message/Forward", "<SummaryView>/Forward"},
-#ifndef GENERIC_UMPC
- {"<Main>/Message/Redirect", "<SummaryView>/Redirect"},
-#endif
- {"<Main>/Message/Move...", "<SummaryView>/Move..."},
- {"<Main>/Message/Copy...", "<SummaryView>/Copy..."},
-#ifndef GENERIC_UMPC
- {"<Main>/Message/Delete...", "<SummaryView>/Delete..."},
-#endif
- {"<Main>/Message/Mark/Mark", "<SummaryView>/Mark/Mark"},
- {"<Main>/Message/Mark/Unmark", "<SummaryView>/Mark/Unmark"},
- {"<Main>/Message/Mark/Mark as unread", "<SummaryView>/Mark/Mark as unread"},
- {"<Main>/Message/Mark/Mark as read", "<SummaryView>/Mark/Mark as read"},
- {"<Main>/Message/Mark/Mark all read", "<SummaryView>/Mark/Mark all read"},
-#ifndef GENERIC_UMPC
- {"<Main>/Tools/Add sender to address book", "<SummaryView>/Add sender to address book"},
-#endif
- {"<Main>/Tools/Create filter rule/Automatically",
- "<SummaryView>/Create filter rule/Automatically"},
- {"<Main>/Tools/Create filter rule/by From", "<SummaryView>/Create filter rule/by From"},
- {"<Main>/Tools/Create filter rule/by To", "<SummaryView>/Create filter rule/by To"},
- {"<Main>/Tools/Create filter rule/by Subject", "<SummaryView>/Create filter rule/by Subject"},
-#ifndef GENERIC_UMPC
- {"<Main>/Tools/Create processing rule/Automatically",
- "<SummaryView>/Create processing rule/Automatically"},
- {"<Main>/Tools/Create processing rule/by From", "<SummaryView>/Create processing rule/by From"},
- {"<Main>/Tools/Create processing rule/by To", "<SummaryView>/Create processing rule/by To"},
- {"<Main>/Tools/Create processing rule/by Subject",
- "<SummaryView>/Create processing rule/by Subject"},
-#endif
- {"<Main>/View/Open in new window", "<SummaryView>/View/Open in new window"},
- {"<Main>/View/Message source", "<SummaryView>/View/Message source"},
-#ifndef GENERIC_UMPC
- {"<Main>/View/All headers", "<SummaryView>/View/All headers"},
-#endif
- };
-
- const gint numpairs = sizeof pairs / sizeof pairs[0];
- for (n = 0; n < numpairs; n++) {
- /* get widgets from the paths */
-
- item1 = gtk_item_factory_get_widget
- (gtk_item_factory_from_path(pairs[n].path1),pairs[n].path1);
- item2 = gtk_item_factory_get_widget
- (gtk_item_factory_from_path(pairs[n].path2),pairs[n].path2);
-
- if (item1 && item2) {
- /* connect widgets both ways around */
- connect_accel_change_signals(item2,item1);
- connect_accel_change_signals(item1,item2);
- } else {
- if (!item1) debug_print(" ** Menu item not found: %s\n",pairs[n].path1);
- if (!item2) debug_print(" ** Menu item not found: %s\n",pairs[n].path2);
- }
- }
-#endif
+ return found;
}