home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / yagirc-0.51.tar.gz / yagirc-0.51.tar / yagirc-0.51 / gui_menufactory.c < prev    next >
C/C++ Source or Header  |  1998-05-09  |  6KB  |  177 lines

  1. /*
  2.  
  3.  gui_menufactory.c : creates main menu..
  4.  
  5.     This file is mostly cut & pasted from GTK+ tutorial so I think it's
  6.     copyrighted by Ian Main <imain@gtk.org> and Tony Gale <gale@gtk.org>
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 2 of the License, or
  11.     (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22.  
  23. #include <gtk/gtk.h>
  24. #include <strings.h>
  25.  
  26. #include "script.h"
  27. #include "gui_menu.h"
  28.  
  29. #if 0
  30. static void menus_remove_accel(GtkWidget * widget, gchar * signal_name, gchar * path);
  31. static gint menus_install_accel(GtkWidget * widget, gchar * signal_name, gchar key, gchar modifiers, gchar * path);
  32. #endif
  33. static void menus_create(WINDOW_REC *win, GtkMenuEntry *entries, int nmenu_entries);
  34.  
  35.  
  36. /* this is the GtkMenuEntry structure used to create new menus.  The
  37.  * first member is the menu definition string.  The second, the
  38.  * default accelerator key used to access this menu function with
  39.  * the keyboard.  The third is the callback function to call when
  40.  * this menu item is selected (by the accelerator key, or with the
  41.  * mouse.) The last member is the data to pass to your callback function.
  42. */
  43.  
  44. static GtkMenuEntry menu_items[] =
  45. {
  46.     {"<Main>/IRC/Connect", NULL, (GtkMenuCallback) menu_irc_connect, NULL},
  47.     {"<Main>/IRC/Disconnect", NULL, (GtkMenuCallback) menu_irc_disconnect, NULL},
  48.     {"<Main>/IRC/Setup...", NULL, (GtkMenuCallback) menu_irc_setup, NULL},
  49.     {"<Main>/IRC/<separator>", NULL, NULL, NULL},
  50.     {"<Main>/IRC/Quit", NULL, (GtkMenuCallback) menu_irc_quit, NULL},
  51.     {"<Main>/Commands/Join...", NULL, (GtkMenuCallback) menu_command_join, NULL},
  52.     {"<Main>/Commands/Part", NULL, (GtkMenuCallback) menu_command_part, NULL},
  53.     {"<Main>/Window/New", NULL, (GtkMenuCallback) menu_window_new, NULL},
  54.     {"<Main>/Window/New hidden", NULL, (GtkMenuCallback) menu_window_new_hidden, NULL},
  55.     {"<Main>/Window/Close", NULL, (GtkMenuCallback) menu_window_close, NULL},
  56.     {"<Main>/Window/Connect...", NULL, (GtkMenuCallback) menu_window_connect, NULL},
  57.     {"<Main>/Help/About", NULL, (GtkMenuCallback) menu_help_about, NULL}
  58. };
  59.  
  60. /* calculate the number of menu_item's */
  61. static int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
  62.  
  63. void gui_menu_create(WINDOW_REC *win)
  64. {
  65.     GtkMenuFactory *menu;
  66.  
  67.     g_return_if_fail(win != NULL);
  68.  
  69.     win->gui->parent->entry_ht = NULL;
  70.     win->gui->parent->factory = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR);
  71.     menu = gtk_menu_factory_new(GTK_MENU_FACTORY_MENU_BAR);
  72.  
  73.     gtk_menu_factory_add_subfactory(win->gui->parent->factory, menu, "<Main>");
  74.     menus_create(win, menu_items, nmenu_items);
  75.  
  76.     win->gui->parent->menubar = menu->widget;
  77.     win->gui->parent->table = menu->table;
  78. }
  79.  
  80. void gui_menu_destroy(WINDOW_REC *win)
  81. {
  82.     /*gtk_menu_factory_destroy(win->gui->parent->factory);
  83.     gtk_widget_destroy(win->gui->parent->menubar);*/
  84. }
  85.  
  86. static void menus_create(WINDOW_REC *win, GtkMenuEntry *entries, int nmenu_entries)
  87. {
  88.     g_return_if_fail(win != NULL);
  89.     g_return_if_fail(entries != NULL);
  90.  
  91. #if 0
  92.     char *accelerator;
  93.     int i;
  94.  
  95.     if (win->gui->parent->entry_ht)
  96.         for (i = 0; i < nmenu_entries; i++) {
  97.             accelerator = g_hash_table_lookup(win->gui->parent->entry_ht, entries[i].path);
  98.             if (accelerator) {
  99.                 if (accelerator[0] == '\0')
  100.                     entries[i].accelerator = NULL;
  101.                 else
  102.                     entries[i].accelerator = accelerator;
  103.             }
  104.         }
  105. #endif
  106.     gtk_menu_factory_add_entries(win->gui->parent->factory, entries, nmenu_entries);
  107.     //script_add_popups(win->gui->parent->factory->widget, POPUPMENU_MAIN, (char *) win);
  108.  
  109. #if 0
  110.     for (i = 0; i < nmenu_entries; i++)
  111.         if (entries[i].widget) {
  112.             gtk_signal_connect(GTK_OBJECT(entries[i].widget), "install_accelerator",
  113.                                (GtkSignalFunc) menus_install_accel,
  114.                                entries[i].path);
  115.             gtk_signal_connect(GTK_OBJECT(entries[i].widget), "remove_accelerator",
  116.                                (GtkSignalFunc) menus_remove_accel,
  117.                                entries[i].path);
  118.         }
  119. #endif
  120. }
  121.  
  122. #if 0
  123. static gint menus_install_accel(GtkWidget *widget, gchar *signal_name, gchar key, gchar modifiers, gchar *path)
  124. {
  125.     char accel[64];
  126.     char *t1, t2[2];
  127.  
  128.     accel[0] = '\0';
  129.     if (modifiers & GDK_CONTROL_MASK)
  130.         strcat(accel, "<control>");
  131.     if (modifiers & GDK_SHIFT_MASK)
  132.         strcat(accel, "<shift>");
  133.     if (modifiers & GDK_MOD1_MASK)
  134.         strcat(accel, "<alt>");
  135.  
  136.     t2[0] = key;
  137.     t2[1] = '\0';
  138.     strcat(accel, t2);
  139.  
  140.     if (win->gui->parent->entry_ht) {
  141.         t1 = g_hash_table_lookup(win->gui->parent->entry_ht, path);
  142.         g_free(t1);
  143.     } else
  144.         win->gui->parent->entry_ht = g_hash_table_new(g_str_hash, g_str_equal);
  145.  
  146.     g_hash_table_insert(win->gui->parent->entry_ht, path, g_strdup(accel));
  147.  
  148.     return TRUE;
  149. }
  150.  
  151. static void menus_remove_accel(GtkWidget *widget, gchar *signal_name, gchar *path)
  152. {
  153.     char *t;
  154.  
  155.     if (win->gui->parent->entry_ht) {
  156.         t = g_hash_table_lookup(win->gui->parent->entry_ht, path);
  157.         g_free(t);
  158.  
  159.         g_hash_table_insert(win->gui->parent->entry_ht, path, g_strdup(""));
  160.     }
  161. }
  162. #endif
  163.  
  164. void menus_set_sensitive(WINDOW_REC *win, char *path, int sensitive)
  165. {
  166.     GtkMenuPath *menu_path;
  167.  
  168.     g_return_if_fail(win != NULL);
  169.     g_return_if_fail(path != NULL);
  170.  
  171.     menu_path = gtk_menu_factory_find(win->gui->parent->factory, path);
  172.     if (menu_path)
  173.         gtk_widget_set_sensitive(menu_path->widget, sensitive);
  174.     else
  175.         g_warning("Unable to set sensitivity for menu which doesn't exist: %s", path);
  176. }
  177.