home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / imagemap / imap_menu_funcs.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-22  |  4.5 KB  |  167 lines

  1. /*
  2.  * This is a plug-in for the GIMP.
  3.  *
  4.  * Generates clickable image maps.
  5.  *
  6.  * Copyright (C) 1998-1999 Maurits Rijk  lpeek.mrijk@consunet.nl
  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21.  *
  22.  */
  23.  
  24. #include "imap_command.h"
  25. #include "imap_menu_funcs.h"
  26.  
  27. static GtkAccelGroup *accelerator_group;
  28.  
  29. void
  30. init_accel_group(GtkWidget *window)
  31. {
  32.    accelerator_group = gtk_accel_group_new();
  33.    gtk_window_add_accel_group(GTK_WINDOW(window), accelerator_group);
  34. }
  35.  
  36. void
  37. add_accelerator(GtkWidget *widget, guchar accelerator_key,
  38.         guint8 accelerator_mods)
  39. {
  40.    gtk_widget_add_accelerator(widget, "activate", accelerator_group,
  41.                   accelerator_key, accelerator_mods,
  42.                   GTK_ACCEL_VISIBLE);
  43. }
  44.  
  45. static GtkWidget*
  46. append_item(GtkWidget *parent, GtkWidget *item)
  47. {
  48.    gtk_menu_append(GTK_MENU(parent), item);
  49.    gtk_widget_show(item);
  50.    return item;
  51. }
  52.  
  53. static GtkWidget*
  54. append_active_item(GtkWidget *parent, GtkWidget *item, MenuCallback activate,
  55.            gpointer data)
  56. {
  57.    gtk_signal_connect(GTK_OBJECT(item), "activate",
  58.               GTK_SIGNAL_FUNC(activate), data);
  59.    return append_item(parent, item);
  60. }
  61.  
  62. /* Fix me: check if 'gpointer data' can work */
  63.  
  64. GtkWidget*
  65. make_item_with_label(GtkWidget *parent, gchar *label, MenuCallback activate,
  66.              gpointer data)
  67. {
  68.    return append_active_item(parent, gtk_menu_item_new_with_label(label),
  69.                  activate, data);
  70. }
  71.  
  72. GtkWidget*
  73. prepend_item_with_label(GtkWidget *parent, gchar *label,
  74.             MenuCallback activate, gpointer data)
  75. {
  76.    GtkWidget *item = gtk_menu_item_new_with_label(label);
  77.    gtk_menu_prepend(GTK_MENU(parent), item);
  78.    gtk_signal_connect(GTK_OBJECT(item), "activate",
  79.               GTK_SIGNAL_FUNC(activate), data);
  80.    gtk_widget_show(item);
  81.  
  82.    return item;
  83. }
  84.  
  85. GtkWidget*
  86. insert_item_with_label(GtkWidget *parent, gint position, gchar *label,
  87.                MenuCallback activate, gpointer data)
  88. {
  89.    GtkWidget *item = gtk_menu_item_new_with_label(label);
  90.    gtk_menu_insert(GTK_MENU(parent), item, position);
  91.    gtk_signal_connect(GTK_OBJECT(item), "activate",
  92.               GTK_SIGNAL_FUNC(activate), data);
  93.    gtk_widget_show(item);
  94.  
  95.    return item;
  96. }
  97.  
  98. GtkWidget*
  99. make_check_item(GtkWidget *parent, gchar *label, MenuCallback activate,
  100.         gpointer data)
  101. {
  102.    return append_active_item(parent, gtk_check_menu_item_new_with_label(label),
  103.                  activate, data);
  104. }
  105.  
  106. GtkWidget*
  107. make_radio_item(GtkWidget *parent, GSList *group, gchar *label,
  108.         MenuCallback activate, gpointer data)
  109. {
  110.    return append_active_item(parent,
  111.                  gtk_radio_menu_item_new_with_label(group, label),
  112.                  activate, data);
  113. }
  114.  
  115. void
  116. make_separator(GtkWidget *parent)
  117. {
  118.    (void) append_item(parent, gtk_menu_item_new());
  119. }
  120.  
  121. void
  122. insert_separator(GtkWidget *parent, gint position)
  123. {
  124.    GtkWidget *item = gtk_menu_item_new();
  125.    gtk_menu_insert(GTK_MENU(parent), item, position);
  126.    gtk_widget_show(item);
  127. }
  128.  
  129.  
  130. GtkWidget*
  131. make_sub_menu(GtkWidget *parent, gchar *label)
  132. {
  133.    GtkWidget *sub_menu = gtk_menu_new();
  134.    GtkWidget *item;
  135.  
  136.    item = append_item(parent, gtk_menu_item_new_with_label(label));
  137.    gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), sub_menu);
  138.  
  139.    return sub_menu;
  140. }
  141.  
  142. GtkWidget*
  143. make_menu_bar_item(GtkWidget *menu_bar, gchar *label)
  144. {
  145.    GtkWidget *menu = gtk_menu_new();
  146.    GtkWidget *item = gtk_menu_item_new_with_label(label);
  147.    GtkWidget *tearoff = gtk_tearoff_menu_item_new();
  148.  
  149.    gtk_menu_insert(GTK_MENU(menu), tearoff, 0);
  150.    gtk_widget_show(tearoff);
  151.    gtk_widget_show(item);
  152.  
  153.    gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
  154.    gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), item);
  155.    gtk_menu_set_accel_group(GTK_MENU(menu), accelerator_group);
  156.  
  157.    return menu;
  158. }
  159.  
  160. void
  161. menu_command(GtkWidget *widget, gpointer data)
  162. {
  163.    CommandFactory_t *factory = (CommandFactory_t*) data;
  164.    Command_t *command = (*factory)();
  165.    command_execute(command);
  166. }
  167.