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_popup.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-23  |  5.4 KB  |  206 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 "config.h"
  25. #include "libgimp/stdplugins-intl.h"
  26.  
  27. #include "imap_edit_area_info.h"
  28. #include "imap_grid.h"
  29. #include "imap_main.h"
  30. #include "imap_menu.h"
  31. #include "imap_menu_funcs.h"
  32. #include "imap_popup.h"
  33. #include "imap_tools.h"
  34.  
  35. static gint _popup_callback_lock;
  36. static PopupMenu_t _popup;
  37.  
  38. void
  39. popup_set_zoom_sensitivity(gint factor)
  40. {
  41.    gtk_widget_set_sensitive(_popup.zoom_in, factor < 8);
  42.    gtk_widget_set_sensitive(_popup.zoom_out, factor > 1);
  43. }
  44.  
  45. static void
  46. popup_rectangle(GtkWidget *widget, gpointer data)
  47. {
  48.    if (_popup_callback_lock) {
  49.       _popup_callback_lock = FALSE;
  50.    } else {
  51.       set_rectangle_func();
  52.       tools_select_rectangle();
  53.       menu_select_rectangle();
  54.    }
  55. }
  56.  
  57. static void
  58. popup_circle(GtkWidget *widget, gpointer data)
  59. {
  60.    if (_popup_callback_lock) {
  61.       _popup_callback_lock = FALSE;
  62.    } else {
  63.       set_circle_func();
  64.       tools_select_circle();
  65.       menu_select_circle();
  66.    }
  67. }
  68.  
  69. static void
  70. popup_polygon(GtkWidget *widget, gpointer data)
  71. {
  72.    if (_popup_callback_lock) {
  73.       _popup_callback_lock = FALSE;
  74.    } else {
  75.       set_polygon_func();
  76.       tools_select_polygon();
  77.       menu_select_polygon();
  78.    }
  79. }
  80.  
  81. static void
  82. popup_arrow(GtkWidget *widget, gpointer data)
  83. {
  84.    if (_popup_callback_lock) {
  85.       _popup_callback_lock = FALSE;
  86.    } else {
  87.       set_arrow_func();
  88.       tools_select_arrow();
  89.       menu_select_arrow();
  90.    }
  91. }
  92.  
  93. static void
  94. popup_grid(GtkWidget *widget, gpointer data)
  95. {
  96.    if (_popup_callback_lock) {
  97.       _popup_callback_lock = FALSE;
  98.    } else {
  99.       gint grid = toggle_grid();
  100.       menu_check_grid(grid);
  101.       main_toolbar_set_grid(grid);
  102.    }
  103. }
  104.  
  105. static void
  106. paste_buffer_added(Object_t *obj, gpointer data)
  107. {
  108.    gtk_widget_set_sensitive((GtkWidget*) data, TRUE);
  109. }
  110.  
  111. static void
  112. paste_buffer_removed(Object_t *obj, gpointer data)
  113. {
  114.    gtk_widget_set_sensitive((GtkWidget*) data, TRUE);
  115. }
  116.  
  117. PopupMenu_t*
  118. create_main_popup_menu(void)
  119. {
  120.    GtkWidget *popup_menu, *sub_menu;
  121.    GtkWidget *paste;
  122.    GSList    *group;
  123.    
  124.    _popup.main = popup_menu = gtk_menu_new();
  125.    make_item_with_label(popup_menu, _("Map Info..."), menu_command, 
  126.             &_popup.cmd_edit_map_info);
  127.    
  128.    sub_menu = make_sub_menu(popup_menu, _("Tools"));
  129.    _popup.arrow = make_radio_item(sub_menu, NULL, _("Arrow"), popup_arrow, 
  130.                   NULL);
  131.    group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(_popup.arrow));
  132.    _popup.rectangle = make_radio_item(sub_menu, group, _("Rectangle"), 
  133.                       popup_rectangle, NULL);
  134.    group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(_popup.rectangle));
  135.    _popup.circle = make_radio_item(sub_menu, group, _("Circle"), 
  136.                    popup_circle, NULL);
  137.    group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(_popup.circle));
  138.    _popup.polygon = make_radio_item(sub_menu, group, _("Polygon"), 
  139.                     popup_polygon, NULL);
  140.    
  141.    sub_menu = make_sub_menu(popup_menu, _("Zoom"));
  142.    _popup.zoom_in = make_item_with_label(sub_menu, _("In"), menu_command, 
  143.                      &_popup.cmd_zoom_in);
  144.    _popup.zoom_out = make_item_with_label(sub_menu, _("Out"), menu_command,
  145.                       &_popup.cmd_zoom_out);
  146.    gtk_widget_set_sensitive(_popup.zoom_out, FALSE);
  147.  
  148.    _popup.grid = make_check_item(popup_menu, _("Grid"), popup_grid, NULL);
  149.    make_item_with_label(popup_menu, _("Grid Settings..."), menu_command,
  150.             &_popup.cmd_grid_settings);
  151.    make_item_with_label(popup_menu, _("Guides..."), menu_command,
  152.             &_popup.cmd_create_guides);
  153.    paste = make_item_with_label(popup_menu, _("Paste"), menu_command, 
  154.                 &_popup.cmd_paste);
  155.    gtk_widget_set_sensitive(paste, FALSE);
  156.    paste_buffer_add_add_cb(paste_buffer_added, (gpointer) paste);
  157.    paste_buffer_add_remove_cb(paste_buffer_removed, (gpointer) paste);
  158.  
  159.    return &_popup;
  160. }
  161.  
  162. void
  163. do_main_popup_menu(GdkEventButton *event)
  164. {
  165.    gtk_menu_popup(GTK_MENU(_popup.main), NULL, NULL, NULL, NULL,
  166.           event->button, event->time);
  167. }
  168.  
  169. static void
  170. popup_select(GtkWidget *item)
  171. {
  172.    _popup_callback_lock = TRUE;
  173.    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
  174. }
  175.  
  176. void
  177. popup_select_arrow(void)
  178. {
  179.    popup_select(_popup.arrow);
  180. }
  181.  
  182. void
  183. popup_select_rectangle(void)
  184. {
  185.    popup_select(_popup.rectangle);
  186. }
  187.  
  188. void
  189. popup_select_circle(void)
  190. {
  191.    popup_select(_popup.circle);
  192. }
  193.  
  194. void
  195. popup_select_polygon(void)
  196. {
  197.    popup_select(_popup.polygon);
  198. }
  199.  
  200. void
  201. popup_check_grid(gboolean check)
  202. {
  203.    _popup_callback_lock = TRUE;
  204.    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_popup.grid), check);
  205. }
  206.