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_tools.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-23  |  5.1 KB  |  198 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 "imap_circle.h"
  26. #include "imap_edit_area_info.h"
  27. #include "imap_main.h"
  28. #include "libgimp/stdplugins-intl.h"
  29. #include "imap_menu.h"
  30. #include "imap_misc.h"
  31. #include "imap_polygon.h"
  32. #include "imap_popup.h"
  33. #include "imap_rectangle.h"
  34. #include "imap_tools.h"
  35.  
  36. #include "arrow.xpm"
  37. #include "rectangle.xpm"
  38. #include "circle.xpm"
  39. #include "polygon.xpm"
  40. #include "delete.xpm"
  41. #include "edit.xpm"
  42.  
  43. static gboolean _callback_lock;
  44. static Tools_t _tools;
  45.  
  46. static void
  47. tools_command(GtkWidget *widget, gpointer data)
  48. {
  49.    CommandFactory_t *factory = (CommandFactory_t*) data;
  50.    Command_t *command = (*factory)();
  51.    command_execute(command);
  52. }
  53.  
  54. void 
  55. arrow_on_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data)
  56. {
  57.    if (event->button == 1) {
  58.       if (event->type == GDK_2BUTTON_PRESS)
  59.      edit_shape((gint) event->x, (gint) event->y);
  60.       else
  61.      select_shape(widget, event);
  62.    } else {
  63.       do_popup_menu(event);
  64.    }
  65. }
  66.  
  67. static void
  68. arrow_clicked(GtkWidget *widget, gpointer data)
  69. {
  70.    if (_callback_lock) {
  71.       _callback_lock = FALSE;
  72.    } else {
  73.       set_arrow_func();
  74.       menu_select_arrow();
  75.       popup_select_arrow();
  76.    }
  77. }
  78.  
  79. static void
  80. rectangle_clicked(GtkWidget *widget, gpointer data)
  81. {
  82.    if (_callback_lock) {
  83.       _callback_lock = FALSE;
  84.    } else {
  85.       set_rectangle_func();
  86.       menu_select_rectangle();
  87.       popup_select_rectangle();
  88.    }
  89. }
  90.  
  91. static void
  92. circle_clicked(GtkWidget *widget, gpointer data)
  93. {
  94.    if (_callback_lock) {
  95.       _callback_lock = FALSE;
  96.    } else {
  97.       set_circle_func();
  98.       menu_select_circle();
  99.       popup_select_circle();
  100.    }
  101. }
  102.  
  103. static void
  104. polygon_clicked(GtkWidget *widget, gpointer data)
  105. {
  106.    if (_callback_lock) {
  107.       _callback_lock = FALSE;
  108.    } else {
  109.       set_polygon_func();
  110.       menu_select_polygon();
  111.       popup_select_polygon();
  112.    }
  113. }
  114.  
  115. Tools_t*
  116. make_tools(GtkWidget *window)
  117. {
  118.    GtkWidget *handlebox;
  119.    GtkWidget *toolbar;
  120.  
  121.    _tools.container = handlebox = gtk_handle_box_new();
  122.    toolbar = gtk_toolbar_new(GTK_ORIENTATION_VERTICAL, GTK_TOOLBAR_ICONS);
  123.    gtk_container_set_border_width(GTK_CONTAINER(toolbar), 5);
  124.    gtk_toolbar_set_space_size(GTK_TOOLBAR(toolbar), 5);
  125.    gtk_container_add(GTK_CONTAINER(handlebox), toolbar);
  126.  
  127.    _tools.arrow = make_toolbar_radio_icon(toolbar, window, NULL, arrow_xpm, 
  128.                       "Select", _("Select existing area"), 
  129.                       arrow_clicked, NULL);
  130.    _tools.rectangle = make_toolbar_radio_icon(toolbar, window, _tools.arrow, 
  131.                           rectangle_xpm, "Rectangle", 
  132.                           _("Define Rectangle area"), 
  133.                           rectangle_clicked, NULL);
  134.    _tools.circle = make_toolbar_radio_icon(toolbar, window, _tools.rectangle, 
  135.                        circle_xpm, "Circle",
  136.                        _("Define Circle/Oval area"), 
  137.                        circle_clicked, NULL);
  138.    _tools.polygon = make_toolbar_radio_icon(toolbar, window, _tools.circle, 
  139.                         polygon_xpm, "Polygon",
  140.                         _("Define Polygon area"), 
  141.                         polygon_clicked, NULL);
  142.    gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
  143.    _tools.edit = make_toolbar_icon(toolbar, window, edit_xpm, "Edit",
  144.                    _("Edit selected area info"), tools_command,
  145.                    &_tools.cmd_edit);
  146.    gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
  147.    _tools.delete = make_toolbar_icon(toolbar, window, delete_xpm, "Delete",
  148.                      _("Delete selected area"), tools_command,
  149.                      &_tools.cmd_delete);
  150.  
  151.    gtk_widget_show(toolbar);
  152.    gtk_widget_show(handlebox);
  153.  
  154.    tools_set_sensitive(FALSE);
  155.    set_arrow_func();
  156.  
  157.    return &_tools;
  158. }
  159.  
  160. static void
  161. tools_select(GtkWidget *widget)
  162. {
  163.    _callback_lock = TRUE;
  164.    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
  165.    gtk_widget_grab_focus(widget);
  166. }
  167.  
  168. void
  169. tools_select_arrow(void)
  170. {
  171.    tools_select(_tools.arrow);
  172. }
  173.  
  174. void
  175. tools_select_rectangle(void)
  176. {
  177.    tools_select(_tools.rectangle);
  178. }
  179.  
  180. void
  181. tools_select_circle(void)
  182. {
  183.    tools_select(_tools.circle);
  184. }
  185.  
  186. void
  187. tools_select_polygon(void)
  188. {
  189.    tools_select(_tools.polygon);
  190. }
  191.  
  192. void
  193. tools_set_sensitive(gboolean sensitive)
  194. {
  195.    gtk_widget_set_sensitive(_tools.edit, sensitive);
  196.    gtk_widget_set_sensitive(_tools.delete, sensitive);
  197. }
  198.