2008-07-26 [colin] 3.5.0cvs35
[claws.git] / src / gtk / menu.c
index 03c75f77571ce547fc988a044cc993f261525d2a..b2c320d7f012b5562ecd929e0af9dea956b04c15 100644 (file)
@@ -4,7 +4,7 @@
  *
  * 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
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
 #include <gtk/gtkitemfactory.h>
 #include <gtk/gtkbutton.h>
 #include <gtk/gtkwindow.h>
+#include <gtk/gtkutils.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) ;
 
@@ -42,14 +53,23 @@ GtkWidget *menubar_create(GtkWidget *window, GtkItemFactoryEntry *entries,
                          guint n_entries, const gchar *path, gpointer data)
 {
        GtkItemFactory *factory;
-
+       GtkWidget *menubar;
+       
+#ifdef MAEMO
+       factory = gtk_item_factory_new(GTK_TYPE_MENU, path, NULL);
+#else
        factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, path, NULL);
+#endif
        gtk_item_factory_set_translate_func(factory, menu_translate,
                                            NULL, NULL);
        gtk_item_factory_create_items(factory, n_entries, entries, data);
        gtk_window_add_accel_group (GTK_WINDOW (window), factory->accel_group);
 
-       return gtk_item_factory_get_widget(factory, path);
+       menubar  = gtk_item_factory_get_widget(factory, path);
+#ifdef MAEMO
+       hildon_window_set_menu(HILDON_WINDOW(window), GTK_MENU(menubar));
+#endif
+       return menubar;
 }
 
 GtkWidget *menu_create_items(GtkItemFactoryEntry *entries,
@@ -64,20 +84,14 @@ GtkWidget *menu_create_items(GtkItemFactoryEntry *entries,
        return gtk_item_factory_get_widget(*factory, path);
 }
 
-GtkWidget *popupmenu_create(GtkWidget *window, GtkItemFactoryEntry *entries,
-                            guint n_entries, const gchar *path, gpointer data)
+GtkActionGroup *cm_menu_create_action_group(const gchar *name, GtkActionEntry *entries,
+                                           gint num_entries, gpointer data)
 {
-       GtkItemFactory *factory;
-       GtkAccelGroup *accel_group;
-
-       accel_group = gtk_accel_group_new();
-       factory = gtk_item_factory_new(GTK_TYPE_MENU, path, accel_group);
-       gtk_item_factory_set_translate_func(factory, menu_translate,
-                                           NULL, NULL);
-       gtk_item_factory_create_items(factory, n_entries, entries, data);
-       gtk_window_add_accel_group(GTK_WINDOW (window), accel_group);
-
-       return gtk_item_factory_get_widget(factory, path);
+       GtkActionGroup *group = gtk_action_group_new(name);
+       gtk_action_group_set_translate_func(group, menu_translate, NULL, NULL);
+       gtk_action_group_add_actions(group, entries, num_entries, data);
+       gtk_ui_manager_insert_action_group(gtkut_ui_manager(), group, 0);
+       return group;
 }
 
 gchar *menu_translate(const gchar *path, gpointer data)
@@ -102,6 +116,44 @@ void menu_set_sensitive(GtkItemFactory *ifactory, const gchar *path,
        gtk_widget_set_sensitive(widget, sensitive);
 }
 
+void cm_menu_set_sensitive(gchar *menu, gboolean sensitive)
+{
+       GtkUIManager *gui_manager = gtkut_ui_manager();
+       GtkWidget *widget;
+       gchar *path = g_strdup_printf("/Menus/%s/", menu);
+
+       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);
+       }
+
+       gtk_widget_set_sensitive(widget, sensitive);
+       g_free(path);
+}
+
+void cm_toggle_menu_set_active(gchar *menu, gboolean active)
+{
+       GtkUIManager *gui_manager = gtkut_ui_manager();
+       GtkWidget *widget;
+       gchar *path = g_strdup_printf("/Menus/%s/", menu);
+
+       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_CHECK_MENU_ITEM(widget) ) {
+               g_message("Blah, '%s' is not a check menu item.\n", path);
+       }
+
+       gtk_check_menu_item_set_active(widget, active);
+       g_free(path);
+}
+
 void menu_set_sensitive_all(GtkMenuShell *menu_shell, gboolean sensitive)
 {
        GList *cur;
@@ -121,7 +173,7 @@ void menu_set_active(GtkItemFactory *ifactory, const gchar *path,
        g_return_if_fail(widget != NULL);
 
        if (!GTK_IS_CHECK_MENU_ITEM(widget)) {
-               debug_print("%s not check_menu_item\n", path);
+               debug_print("%s not check_menu_item\n", path?path:"(null)");
                return;
        }       
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), is_active);
@@ -187,17 +239,6 @@ gint menu_find_option_menu_index(GtkOptionMenu *optmenu, gpointer data,
        return -1;
 }
 
-gpointer menu_get_option_menu_active_user_data(GtkOptionMenu *optmenu)
-{
-       GtkWidget *menu;
-       GtkWidget *menuitem;
-
-       menu = gtk_option_menu_get_menu(optmenu);
-       menuitem = gtk_menu_get_active(GTK_MENU(menu));
-
-       return g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID);
-}
-
 static void connect_accel_change_signals(GtkWidget* widget, GtkWidget *wid2) 
 {
 #if 0
@@ -219,34 +260,46 @@ void menu_connect_identical_items(void)
                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];
@@ -268,27 +321,3 @@ void menu_connect_identical_items(void)
                }                               
        }
 }
-
-void menu_select_by_data(GtkMenu *menu, gpointer data)
-{
-       GList *children, *cur;
-       GtkWidget *select_item = NULL;
-       
-       g_return_if_fail(menu != NULL);
-
-       children = gtk_container_get_children(GTK_CONTAINER(menu));
-
-       for (cur = children; cur != NULL; cur = g_list_next(cur)) {
-               GObject *child = G_OBJECT(cur->data);
-
-               if (g_object_get_data(child, MENU_VAL_ID) == data) {
-                       select_item = GTK_WIDGET(child);
-               }
-       }
-       if (select_item != NULL) {
-               gtk_menu_shell_select_item(GTK_MENU_SHELL(menu), select_item);
-               gtk_menu_shell_activate_item(GTK_MENU_SHELL(menu), select_item, FALSE);
-       }
-
-       g_list_free(children);
-}